chart.setNotify() and dataset changes

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
colomb
Posts: 15
Joined: Fri May 29, 2009 8:10 pm

chart.setNotify() and dataset changes

Post by colomb » Fri May 11, 2012 5:20 pm

I'm seeing some puzzling behavior. I have a chart with one TimeTableXYDataset with 10 series in it. I update the chart clearing the dataset then iterating over an internal datastructure and adding points back into the dataset. Chart updating seemed a little slow so I wrapped the dataset modification in chart.setNotify(false/true). Nothing changed. I then used the dataset.add() method with the option of not notifying listeners and once the dataset update is done, I invoke datasetChanged() on the plot object. This works as I'd expect and is fast. The questions I have as:

1) Shouldn't using setNotify() do the same thing as adding points to a dataset with no notification and then notify the plot that the dataset has updated?
2) Why is the later method so much faster than using setNotify()?
3) What are the recommended best practices when updating chart data? Thanks,

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: chart.setNotify() and dataset changes

Post by paradoxoff » Sun May 13, 2012 5:46 pm

Hi colomb,
when you call chart.setNotify(false), you only prevent the chart from telling its ChartChangeListeners that something has changed. if the chart is visible on screen in a ChartPanel, the ChartPanel will repaint itself. If the chart is not visible, it is conceivable that no ChartChangeListener is notified. In this case, calling chart.setNotify(false) will gain you nothing.
However, there might still be a lot going on when a dataset is updated, most importantly the calculation of new value ranges for the domain and range axes. Depending on the autorange settings for the axis, each addition of a value might trigger this recalculation. Depending on how much data you are inserting this might take some time.
This recalculation is prohibited when you first add all your data to the dataset and only carried out once (once you call datasetChanged()).
Having (hopefully) answere q1 and q2, one hint concerning q3: If you have a separate data structure, it is normally not the best approach to transfer the data from your data structure to one of JFreeChart XYDataset implementations. it is normally better to create your own XYDataset (or TableXYDataset) implementation that allows the plot to directly access the values in your data structure. Having your own implementation is giving you also full control about the point at which fireDatasetChanged() is called by the dataset, which will trigger the sequence of actions outlined above.

colomb
Posts: 15
Joined: Fri May 29, 2009 8:10 pm

Re: chart.setNotify() and dataset changes

Post by colomb » Tue May 15, 2012 3:27 pm

Thanks, that all makes sense.

Any idea why DefaultCategoryDataset doesn't have a method that allows you to add values without calling fireDatasetChanged()?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: chart.setNotify() and dataset changes

Post by paradoxoff » Tue May 15, 2012 10:04 pm

colomb wrote: Any idea why DefaultCategoryDataset doesn't have a method that allows you to add values without calling fireDatasetChanged()?
No, no idea. Such a method but be a good thing to have.

colomb
Posts: 15
Joined: Fri May 29, 2009 8:10 pm

Re: chart.setNotify() and dataset changes

Post by colomb » Tue May 15, 2012 10:38 pm


Locked