| | |
Trend charts from text files
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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).
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 0
well after reading the manual and adapting some code of my own....
i have some dificulties regarding the translation of the data of the txt file... is not plotting...
Java Syntax (Toggle Plain Text)
package Ekra; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.*; import java.util.*; import java.lang.NumberFormatException; import java.text.NumberFormat; import java.text.MessageFormat; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.StandardXYItemRenderer; import org.jfree.data.*; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.data.DomainOrder; import org.jfree.data.general.SeriesDataset; import org.jfree.data.category.DefaultCategoryDataset; public class graph extends JFrame{ /** * */ private static final long serialVersionUID = 0L; public graph(String title) throws Exception{ super(title); XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); chartPanel.setMouseZoomable(true, false); } // 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 // 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 ...) // What I'm trying to do is get two of those column (now in double) and put points on the method series.add below // 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 // My attempt was a normal access to the txt file /* public extrator extract(String) throws Exception { File file = new File("F:\\Ekralog.txt"); FileInputStream in = new FileInputStream(file); InputStreamReader convert = new InputStreamReader(in); BufferedReader bf = new BufferedReader(convert); String line; String[] element; line = bf.readLine(); element = line.split("[\\s]+"); bf.close(); in.close();return */ private XYDataset createDataset() throws Exception { //CONVERT STRING TO DOUBLE //double element0; //element0 = Double.parseDouble(element[0]); /* element[0] its one string*/ XYSeries series1 = new XYSeries("TRZ"); series1.add(1.0, 1.0); // some point that i've inserted to test and it is series1.add(2.0, 4.0);// should i do a loop to test it.. there are more than 100 points series1.add(3.0, 3.0); series1.add(4.0, 5.0); series1.add(5.0, 5.0); series1.add(6.0, 7.0); series1.add(7.0, 7.0); series1.add(8.0, 8.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); return dataset; } // ListDouble colunas = new ArrayListDouble(); //public ListDouble getColunas(){ // return colunas; // } private JFreeChart createChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart( "Medida", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); return chart; } public static void main(String[] args) throws Exception { graph teste = new graph("test"); teste.pack(); teste.setVisible(true); } }
i have some dificulties regarding the translation of the data of the txt file... is not plotting...
![]() |
Other Threads in the Java Forum
- Previous Thread: Swing layout misbehaviour
- Next Thread: Printing a JTextArea
Views: 911 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






