I have an application that wants to use JFreeChart to maintain a continuous
display of the last N values of a continuously growing series of <x, y> data points.
The series grows by appending points in increasing x order.
Can I do this correctly, efficiently, and frequently by side-effecting my XYDataSet
and calling JFreeChart.fireChartChanged() or datasetChanged() ? I think I can
promise that
((i <= j) || (t1 <= t2))
implies
dataset.getXValue(s, i) at time t1 will return a value less than or equal to dataset.getXValue(s, j) at time t2 .
That is what I am currently doing, and I am getting BadPath exceptions,
and wondering if this is due to concurrency problems.
What about the alternative of creating a new XYDataset every time my underlying
series grows, and calling JFreeChart.setDataset() ? Will that be noticeably
more correct or less efficient (I'm asking about the efficiency on JFreeChart's side; I'll worry about how to implement this series of XYDatasets)?
Thanks,
Mike
Correct, efficient, frequent updates of XY plots
Re: Correct, efficient, frequent updates of XY plots
I goofed up that condition I can promise. It should be
((i <= j) && (t1 <= t2))
implies
dataset.getXValue(s, i) at time t1 <= dataset.getXValue(s, j) at time t2.
I think I can also promise this:
((i < j) && (t1 <= t2))
implies
dataset.getXValue(s, i) at time t1 < dataset.getXValue(s, j) at time t2.
((i <= j) && (t1 <= t2))
implies
dataset.getXValue(s, i) at time t1 <= dataset.getXValue(s, j) at time t2.
I think I can also promise this:
((i < j) && (t1 <= t2))
implies
dataset.getXValue(s, i) at time t1 < dataset.getXValue(s, j) at time t2.
Re: Correct, efficient, frequent updates of XY plots
Hi Mike,
XYDataset has the methods addDatasetChangeListener(...) and removeDatasetChangeListener(...). When you implement your own dataset class, you need to notify the listeners any time the dataset changes. The default behaviour is that the chart is completely redrawn whenever the dataset changes...the same thing happens if you completely replace the dataset. In the future, I'd like to incorporate more information in the change event so that the chart can react more intelligently (and, say, not redraw the chart if the data change doesn't affect the visible data range).
A related area where JFreeChart needs improving is the way it uses the data it is plotting. At the moment, the chart drawing just iterates through all the data, even though a lot of the data might not be visible. And the auto range calculations for the axes look at all the data, not just the visible data...which needs fixing.
The 'bad path' exception you mention is probably due to the drawing methods plotting some data that is well off the chart. At the moment, JFreeChart relies on the Java2D clipping to make sure the plotted data doesn't appear anywhere. But if you end up drawing a line that has very large coordinates (which Line2D.Double allows) you will get these 'bad path' exceptions. Most of these can probably be eliminated by making JFreeChart more selective about which data it actually draws...but it would be helpful if the Java2D library took care of the large coordinates automatically.
Regards,
DG.
XYDataset has the methods addDatasetChangeListener(...) and removeDatasetChangeListener(...). When you implement your own dataset class, you need to notify the listeners any time the dataset changes. The default behaviour is that the chart is completely redrawn whenever the dataset changes...the same thing happens if you completely replace the dataset. In the future, I'd like to incorporate more information in the change event so that the chart can react more intelligently (and, say, not redraw the chart if the data change doesn't affect the visible data range).
A related area where JFreeChart needs improving is the way it uses the data it is plotting. At the moment, the chart drawing just iterates through all the data, even though a lot of the data might not be visible. And the auto range calculations for the axes look at all the data, not just the visible data...which needs fixing.
The 'bad path' exception you mention is probably due to the drawing methods plotting some data that is well off the chart. At the moment, JFreeChart relies on the Java2D clipping to make sure the plotted data doesn't appear anywhere. But if you end up drawing a line that has very large coordinates (which Line2D.Double allows) you will get these 'bad path' exceptions. Most of these can probably be eliminated by making JFreeChart more selective about which data it actually draws...but it would be helpful if the Java2D library took care of the large coordinates automatically.
Regards,
DG.