Delaying Chart Redraw

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
oas

Delaying Chart Redraw

Post by oas » Mon Nov 25, 2002 9:53 pm

I have an app that displays a single chart. The chart can be changed to display various quantities. I'm looking for the best way to redraw the chart and avoid any flicker. The chart currently has 3 series overlayed in an XY plot. To draw a new plot, I clear the original series and add new points. When I do this, the plot visually changes a few times while I'm altering it. What I'd like to do is something like this:

chart.redraw(false);

modify chart

chart.redraw(true);

I've implemented this to some extent by hiding the chart, making the changes and then unhiding it, but I'm hoping there is a better approach.

Thanks

Klaus Rheinwald

Re: Delaying Chart Redraw

Post by Klaus Rheinwald » Tue Nov 26, 2002 7:37 pm

Apply the following changes to JFreeChart.java, compile and replace the resulting .class in jfreechart.0.9.4.jar.

Please let me know, whether it works, so I can file an RFE.

Klaus

---

private static boolean autoUpdate = true; // Added

/**
* Set mode of automatic chart update.
*
* @param autoUpdate mode to set.
*/
public void setAutoUpdate( boolean autoUpdate) { // Added
this.autoUpdate = autoUpdate; // Added
notifyListeners(new ChartChangeEvent(this)); // Added
} // Added

/**
* Sends a ChartChangeEvent to all registered listeners.
*
* @param event information about the event that triggered the notification.
*/
protected void notifyListeners(ChartChangeEvent event) {

if( autoUpdate) { // Added
Object[] listeners = this.listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners == ChartChangeListener.class) {
((ChartChangeListener) listeners[i + 1]).chartChanged(event);
}
}
} // Added
}

oas

Re: Delaying Chart Redraw

Post by oas » Tue Nov 26, 2002 9:51 pm

It works perfectly. Thanks.

Dave Gilbert

Re: Delaying Chart Redraw

Post by Dave Gilbert » Wed Nov 27, 2002 1:18 pm

Hi Klaus,

That looks like a good addition, I'll incorporate it for the next release.

Regards,

DG

Klaus Rheinwald

Re: Delaying Chart Redraw

Post by Klaus Rheinwald » Mon Feb 10, 2003 5:51 pm

Unfortunatly, this didn't make it into 0.9.5. :-(

Mark Coffey

Re: Delaying Chart Redraw

Post by Mark Coffey » Tue Feb 11, 2003 12:49 am

What about delaying the update of a series, or a collection of series, as well? I am using JFreeChart to display real time statistics. Several BasicTimeSeries (version 0.9.4) compose a TimeSeriesCollection. Each BasicTimeSeries can belong to multiple TimeSeriesCollections (or none at all). Instead of firing a notification to the TimeSeriesCollection each time one of it's BasicTimeSeries was updated, it would be great if there was a batch update. This way the graph displaying the TimeSeriesCollection would only get updated once for all the BasicTimeSeries updates in the batch, instead of each time a single BasicTimeSeries received new data.
Something along the lines of:

someTimeSeriesCollection.beginBatchUpdate();
basicTimeSeries1.add(someDataPair1);
basicTimeSeries2.add(someDataPair2);
...
somtTimeSeriesCollection.endBatchUpdate();

The endBatchUpdate method would then fire the notification to all the listeners and the graphs would get updated appropriately.

David Gilbert

Re: Delaying Chart Redraw

Post by David Gilbert » Tue Feb 11, 2003 9:56 am

Hi Klaus,

Please accept my apology...I forgot to make the change for 0.9.5. I've now committed the change to CVS, so it will be included in 0.9.6. I changed the name to 'get/setSuppressChartChangeEvents(...)', but otherwise it does the same thing.

Regards,

Dave Gilbert

David Gilbert

Re: Delaying Chart Redraw

Post by David Gilbert » Tue Feb 11, 2003 9:59 am

Hi Mark,

I've added your feature request to the database on SourceForge. The id is 684460.

Regards,

Dave Gilbert

Irv Thomae

Re: Delaying Chart Redraw

Post by Irv Thomae » Tue Feb 11, 2003 4:02 pm

Mark,
If, for every new time interval, you have a new data point for each and every series, it is possible that the DynamicTimeSeriesCollection class might help you.
Its appendData(float []) method is very nearly equivalent to the BatchUpdate() methods you suggest.
For each new time interval, instead of adding time-data pairs one by one, appendData() updates all of the series from the array of values passed - and only then does it trigger a display update. Internally, the class uses a single array of time values instead of maintaining distinct (and redundant) time-value pairs for each data series.
In my own application, I use it like this: (assuming a DynamicTimeSeriesCollection object called "dataToShow" :)

float[] newData;
for (int i = 0; i < NumberOfSeries; i++)
newData = whatever(i);
synchronized (dataToShow)
{
dataToShow.advanceTime(); // appends the next TimePeriod
dataToShow,appendData(newData);
}

I hope this pseudo-code is enough to let you decide whther to look into it further.

Irv Thomae
ISTS/IRIA/Dartmouth College
Hanover, NH (USA)

Mark Coffey

Re: Delaying Chart Redraw

Post by Mark Coffey » Tue Feb 11, 2003 6:35 pm

I took a look at the DynamicTimeSeriesCollection Javadoc. This would be helpful if all of the series were to be visible at all times. In the application I am developing the user is able to select which lines are visible in the graph. The TimeSeriesCollection works well with this because BasicTimeSeries can be removed from the TimeSeriesCollection and new ones can be added back. Since the TimeSeriesCollection object is the same, the graph automatically updates each time a series is added or removed.

Another aspect of this functionality to be considered is that this application is multi-threaded. There is a data-gathering thread that populates the BasicTimeSeries. The main thread handles displaying the graphs. In order for the data-gathering thread to know which TimeSeriesCollections are registered as listeners to the BasicTimeSeries, a getChangeListeners() method would need to be added to the com.jrefinery.data.Series class. This way, the data-gathering thread could set all the listening TimeSeriesCollections to not auto-update until all the new data is loaded in the BasicTimeSeries.

Should this request for a getChangeListeners() method be added to the
current feature request or should a new one be opened?

Mark Coffey

Re: Delaying Chart Redraw

Post by Mark Coffey » Thu Feb 13, 2003 12:09 am

What is the normal procedure for requesting a new feature? Should a topic be posted here and Dave Gilbert posts the feature request on SourceForge, or can anyone do that directly?

Locked