A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
theAnonymous
- Posts: 11
- Joined: Tue Feb 22, 2011 8:15 pm
- antibot: No, of course not.
Post
by theAnonymous » Fri May 06, 2011 12:09 am
i am charting something that needs to continually take in new data without discarding old data.
1) is there a way to do this without drawing a new chart altogether? is there a way to append to an already existing XYPlot?
2) at the moment, i am redrawing the whole chart, but the chart disappears unless i click the panel that the chart is in. the code looks something like that. it's ok on the first run, though.
Code: Select all
JPanel panel; //initialised in constructor
private void refreshChart(){
panel.removeAll();
panel.repaint(); // this statement causes the chart to disappear
JFreeChart chart = createChart();
chart.removeLegend();
ChartPanel chartPanel = new ChartPanel(chart);
panel.setLayout(new BorderLayout());
panel.add(chartPanel);
panel.repaint(); //this statement does not cause the new chart to appear... unless i click anywhere in the panel
}
please help, thanks.
-
mayuri2411
- Posts: 1
- Joined: Wed Feb 27, 2013 6:25 am
- antibot: No, of course not.
Post
by mayuri2411 » Wed Feb 27, 2013 11:04 am
I also have similar problem please reply
-
sjoerd
- Posts: 3
- Joined: Tue Feb 26, 2013 1:17 pm
- antibot: No, of course not.
Post
by sjoerd » Wed Feb 27, 2013 2:35 pm
Can't you just append new data to the series in your dataset? The chart should repaint itself automatically when the dataset changes.
Something like:
Code: Select all
private XYSeriesCollection dataset;
private void createDataset()
{
dataset = new XYSeriesCollection();
XYSeries series = new XYSeries("First");
series.add(1, 25);
series.add(35, 30);
XYSeries series2 = new XYSeries("Second");
series2.add(1, 10);
series2.add(20, 10);
dataset.addSeries(series);
dataset.addSeries(series2);
}
public void updateData()
{
for ( int i=0; i<dataset.getSeriesCount(); i++ )
{
dataset.getSeries(i).add(60, 10);
}
}
-
gavin_gj
- Posts: 1
- Joined: Fri Apr 19, 2013 12:02 am
- antibot: No, of course not.
Post
by gavin_gj » Fri Apr 19, 2013 12:12 am
Hello
We have a similar issue. We have quite large datasets.
"The chart should repaint itself automatically when the dataset changes." - true; this repaint takes a significant length of time for us (0.5 seconds; a problem as new data can arrive 10 times per second!).
If the new data points being added were written to an existing (offscreen) canvas, rather than repainting (re-rendering) the whole thing, we would have no such performance issues. (Given that our usage is add-only ; e don't remove data points; or if we do, we can do a full repaint / re-render at that time).
Has anyone faced or solved this issue? Or is there perhaps another library that might be better for this sort of thing (large data sets, near-real-time)?
JFree chart is great in all other regards; it is just that the architecture may not suit our usage re the way it repaints / rerenders the whole chart.
Regards
Gavin
-
paradoxoff
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Post
by paradoxoff » Fri Apr 19, 2013 11:56 am
A simple approach could be to lower the frequency in which the DatasetChangeEvents are fired. You could write your own XYDataset implementation that extends AbstractXYDataset and stores the data in a custom data structure, such as an ArrayList<double[2]>. At given intervals, you would simply have to call fireDatasetChanged() to start the event notification chain. You woud just have to make sure that the access to the custom data structure is synchronized.
It would certainly be better to create an offscreen image after the first rendering cycle is complete and for subsequent rendering steps simply draw the image and new points on top, but that would be far more work. Under certain circumstance, the offscreen image would have to be refreshed even if no new data points have been added, e. g. if the axis range or the size of the data area have changed.