How to add dynamic values from a text file.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
SthatycSoul
Posts: 2
Joined: Tue Sep 27, 2016 6:33 pm
antibot: No, of course not.

How to add dynamic values from a text file.

Post by SthatycSoul » Tue Sep 27, 2016 6:54 pm

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.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: How to add dynamic values from a text file.

Post by John Matthews » Wed Sep 28, 2016 12:35 am

A complete example is examined here.

SthatycSoul
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.

Post by SthatycSoul » Wed Sep 28, 2016 9:04 pm

John Matthews wrote:A complete example is examined here.
Thank you, but I dont want something like that...

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. :)

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: How to add dynamic values from a text file.

Post by John Matthews » Thu Sep 29, 2016 4:11 am

I'm not sure where you're stuck. Use ChartUtilities to save the chart as a PNG.

Locked