943,608 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1179
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 13th, 2008
0

Re: Trend charts from text files

Once again: take a look at JFreeChart.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007
Nov 13th, 2008
0

Re: Trend charts from text files

Thank you for the Tip... i'm reading the documentation related to Jfreechart...

Did you ever work with it? any advices?
Reputation Points: 7
Solved Threads: 0
Light Poster
jorgeflorencio is offline Offline
45 posts
since Apr 2008
Nov 13th, 2008
0

Re: Trend charts from text files

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007
Nov 13th, 2008
0

Re: Trend charts from text files

Thank you for the tip
Reputation Points: 7
Solved Threads: 0
Light Poster
jorgeflorencio is offline Offline
45 posts
since Apr 2008
Nov 13th, 2008
0

Re: Trend charts from text files

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).
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Nov 14th, 2008
0

Re: Trend charts from text files

well after reading the manual and adapting some code of my own....


Java Syntax (Toggle Plain Text)
  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...
Reputation Points: 7
Solved Threads: 0
Light Poster
jorgeflorencio is offline Offline
45 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Swing layout misbehaviour
Next Thread in Java Forum Timeline: Resources for hashing?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC