Hello, I try to add to my chart a dynamic values, reading from a text file.
I create a: bufferedreader, to read the file, and add the value from the text file to the chart...
Here all work's fine, but the problem is, just add the first value of the text file, and not the rest.
I want to read all the values, line by line, and add to the chart one by one and graph.
Here is my code:[
//Buffer's.
BufferedReader Breader1 = new BufferedReader(new FileReader("C:\\Users\\Oscar\\Desktop\\Non.txt"));
StringBuilder Sbuilder = new StringBuilder();
St1 = Breader1.readLine();
try{
Db1 = Integer.parseInt(St1);
}catch(Exception a){
System.out.println("Error.");
}
//Data's.
DefaultCategoryDataset Data1 = new DefaultCategoryDataset();
while((St1 = Breader1.readLine()) != null){
Data1.addValue(Db1, "Use.", "00:05");
St1 = Breader1.readLine();
Data1.addValue(Db1, "Use.", "00:10");
Data1.addValue(99, " ", " ");
}
//Chart's.
JFreeChart Chart1 = ChartFactory.createLineChart("Rsc.", " ", " ", Data1,PlotOrientation.VERTICAL,
true, true, false);
//Image's.
ChartUtilities.saveChartAsPNG(new File("C:\\Users\\Oscar\\Desktop\\Ph.png"), Chart1, 900, 490);
//Frame's.
ChartFrame Frame1 = new ChartFrame("Use.", Chart1);
Frame1.pack();
Frame1.setLocationRelativeTo(null);
Frame1.setVisible(true);
}
}]
Finally create a image with the print values on the chart, ¿Somebody have idea, to how can I do it this?
I try creating a for loop, but not work's... I really apreciate your time, and help.
Thank you, regards.
How to add dynamic values from a text file.
-
- Posts: 2
- Joined: Tue Sep 27, 2016 6:33 pm
- antibot: No, of course not.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: How to add dynamic values from a text file.
A complete example is examined here.
-
- Posts: 2
- Joined: Tue Sep 27, 2016 6:33 pm
- antibot: No, of course not.
Re: How to add dynamic values from a text file.
Thank you, but I dont want something like that...John Matthews wrote:A complete example is examined here.
I just want to create a static chart, not a frame. I want my program read a text file with values, lyne by line, and add value by value, when this is made, create a PNG, with the chart with all the values in the graph...
But actually, I cant do it this, I can just graph the fisrt line of my text file in the chart...
¿Have you idea to do this? I really apreciate your time and help, regards.
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: How to add dynamic values from a text file.
I'm not sure where you're stuck. Use ChartUtilities to save the chart as a PNG.