Maybe I just missed something, but I have not been able to find (including looking in the developer guide) any method for updating the data in a series of a chart/plot.
I would like to essentially reload the y-data after a listener is triggered. Currently I am just plotting a whole new window, but this is obviously kinda clumsy.
Any pointers on documentation is appreciated.
Update dataset
-
- Posts: 513
- Joined: Wed Sep 12, 2007 3:18 pm
Re: Update dataset
In this example, the setValue() method of DefaultCategoryDataset "updates a value in the table and sends a DatasetChangeEvent to all registered listeners." The listening view updates itself in response.
Re: Update dataset
Thanks John,
So is DefaultCategoryDataset the only dataset type that will update in this way? ...trying to avoid rewriting all the XYdatasets I'm using
So is DefaultCategoryDataset the only dataset type that will update in this way? ...trying to avoid rewriting all the XYdatasets I'm using
Re: Update dataset
Also this dataset type does not seem to support double values for the x-axis
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Update dataset
All datasets that are part of the JFreeChart package will start an event chain that will finally lead to an updated "window" (if the window is a ChartWindow or if the window contains a ChartPanel).
You only need to keep a reference to the dataset an update it with new data. Note that some datasets do miss methods to update them. For example, DefaultOHLCDataset and DefaultHighLowDataset appear to be effectively "read-only", but the mroe "conventional" ones like DefaultCategoryDataset, DefaultXYDataset and XYSeriesCollection can be updated after construction.
You could also keep a reference to the XYPlot, and simply replace an outdated dataset with one containing new data. Though this approach creates a bit more overhead that simply updating the dataset, it is simpler to implement, and is certainly far more effective than recreating the entire window.
You only need to keep a reference to the dataset an update it with new data. Note that some datasets do miss methods to update them. For example, DefaultOHLCDataset and DefaultHighLowDataset appear to be effectively "read-only", but the mroe "conventional" ones like DefaultCategoryDataset, DefaultXYDataset and XYSeriesCollection can be updated after construction.
You could also keep a reference to the XYPlot, and simply replace an outdated dataset with one containing new data. Though this approach creates a bit more overhead that simply updating the dataset, it is simpler to implement, and is certainly far more effective than recreating the entire window.