Trend charts from text files

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2007
Posts: 4,515
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Trend charts from text files

 
0
  #11
Nov 13th, 2008
Once again: take a look at JFreeChart.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: jorgeflorencio is an unknown quantity at this point 
Solved Threads: 0
jorgeflorencio jorgeflorencio is offline Offline
Light Poster

Re: Trend charts from text files

 
0
  #12
Nov 13th, 2008
Thank you for the Tip... i'm reading the documentation related to Jfreechart...

Did you ever work with it? any advices?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,515
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Trend charts from text files

 
0
  #13
Nov 13th, 2008
Yes, we use it for some scatter plot and bar charts. There are many built-in graph types for various data series. Look through the demo jar that accompanies the download for a lot of examples of the various charts.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: jorgeflorencio is an unknown quantity at this point 
Solved Threads: 0
jorgeflorencio jorgeflorencio is offline Offline
Light Poster

Re: Trend charts from text files

 
0
  #14
Nov 13th, 2008
Thank you for the tip
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: Trend charts from text files

 
0
  #15
Nov 13th, 2008
I think you are at a stage where you need to start producing some code to enable us to help you out more. Make sure next time you post, you have some code (use code tags too) you are struggling with (try make it relevant code, we don't need your whole program).
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: jorgeflorencio is an unknown quantity at this point 
Solved Threads: 0
jorgeflorencio jorgeflorencio is offline Offline
Light Poster

Re: Trend charts from text files

 
0
  #16
Nov 14th, 2008
well after reading the manual and adapting some code of my own....


  1. package Ekra;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.InputStreamReader;
  6. import java.io.BufferedReader;
  7. import java.io.*;
  8. import java.util.*;
  9. import java.lang.NumberFormatException;
  10. import java.text.NumberFormat;
  11. import java.text.MessageFormat;
  12.  
  13. import java.awt.Font;
  14. import javax.swing.JFrame;
  15. import javax.swing.JPanel;
  16. import org.jfree.chart.ChartFactory;
  17. import org.jfree.chart.ChartPanel;
  18. import org.jfree.chart.JFreeChart;
  19. import org.jfree.chart.plot.PiePlot;
  20. import org.jfree.data.general.DefaultPieDataset;
  21.  
  22. import org.jfree.chart.ChartFactory;
  23. import org.jfree.chart.ChartPanel;
  24. import org.jfree.chart.JFreeChart;
  25. import org.jfree.chart.axis.NumberAxis;
  26. import org.jfree.chart.plot.PlotOrientation;
  27. import org.jfree.chart.plot.XYPlot;
  28. import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
  29. import org.jfree.data.*;
  30. import org.jfree.data.xy.XYDataset;
  31. import org.jfree.data.xy.XYSeries;
  32. import org.jfree.data.xy.XYSeriesCollection;
  33. import org.jfree.data.DomainOrder;
  34. import org.jfree.data.general.SeriesDataset;
  35. import org.jfree.data.category.DefaultCategoryDataset;
  36.  
  37.  
  38. public class graph extends JFrame{
  39.  
  40. /**
  41. *
  42. */
  43. private static final long serialVersionUID = 0L;
  44.  
  45. public graph(String title) throws Exception{
  46.  
  47. super(title);
  48.  
  49. XYDataset dataset = createDataset();
  50. JFreeChart chart = createChart(dataset);
  51. ChartPanel chartPanel = new ChartPanel(chart);
  52. chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
  53. setContentPane(chartPanel);
  54. chartPanel.setMouseZoomable(true, false);
  55. }
  56.  
  57.  
  58. // Well, here I read a file from a table in txt each line with 4 columns of numbers), save it in a string and then on a string
  59. // Array of 4 elements. Then convert each element of the string to double (not know if I'm being very stupid, I am more beginner in java ...)
  60. // What I'm trying to do is get two of those column (now in double) and put points on the method series.add below
  61. // I think I have to do a loop of some way, then do what you suggested q ... But the loop that I did overwrite the variables
  62. // My attempt was a normal access to the txt file
  63.  
  64. /* public extrator extract(String) throws Exception {
  65.   File file = new File("F:\\Ekralog.txt");
  66.   FileInputStream in = new FileInputStream(file);
  67.   InputStreamReader convert = new InputStreamReader(in);
  68.   BufferedReader bf = new BufferedReader(convert);
  69.   String line;
  70.   String[] element;
  71.   line = bf.readLine();
  72.   element = line.split("[\\s]+");
  73.   bf.close();
  74.   in.close();return
  75.  
  76. */
  77.  
  78.  
  79. private XYDataset createDataset() throws Exception {
  80. //CONVERT STRING TO DOUBLE
  81. //double element0;
  82. //element0 = Double.parseDouble(element[0]); /* element[0] its one string*/
  83.  
  84. XYSeries series1 = new XYSeries("TRZ");
  85. series1.add(1.0, 1.0); // some point that i've inserted to test and it is
  86. series1.add(2.0, 4.0);// should i do a loop to test it.. there are more than 100 points
  87. series1.add(3.0, 3.0);
  88. series1.add(4.0, 5.0);
  89. series1.add(5.0, 5.0);
  90. series1.add(6.0, 7.0);
  91. series1.add(7.0, 7.0);
  92. series1.add(8.0, 8.0);
  93.  
  94.  
  95.  
  96. XYSeriesCollection dataset = new XYSeriesCollection();
  97. dataset.addSeries(series1);
  98.  
  99. return dataset;
  100.  
  101.  
  102. }
  103. // ListDouble colunas = new ArrayListDouble();
  104.  
  105. //public ListDouble getColunas(){
  106.  
  107. // return colunas;
  108.  
  109. // }
  110.  
  111.  
  112. private JFreeChart createChart(XYDataset dataset) {
  113. // create the chart...
  114. JFreeChart chart = ChartFactory.createXYLineChart(
  115. "Medida", // chart title
  116. "X", // x axis label
  117. "Y", // y axis label
  118. dataset, // data
  119. PlotOrientation.VERTICAL,
  120. true, // include legend
  121. true, // tooltips
  122. false // urls
  123.  
  124. );
  125.  
  126. return chart;
  127. }
  128.  
  129. public static void main(String[] args) throws Exception {
  130. graph teste = new graph("test");
  131. teste.pack();
  132. teste.setVisible(true);
  133. }
  134.  
  135. }

i have some dificulties regarding the translation of the data of the txt file... is not plotting...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 904 | Replies: 15
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC