Real-time usage slowdown

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Real-time usage slowdown

Post by Siniz » Wed Sep 10, 2008 9:39 am

I've got some problems with JFReeChart beeing really slow in real-time. I am basically using the charts for real-time purposes where I draw 7 different charts (4 xyplots as with timeaxises, and three bar or dial charts). I am guessing it's the timeseries chart that are slow? Would using DynamicTimeSeriesCollection fix this?

What I do is to run through a loop every 100ms where I add (or change in the case of a bar/dial chart) values. Is this bound to be really slow? What happens is that it takes like 4 seconds to actually go through 1 second. So it's 4x as slow as it should be.

Here's pretty much all code used every 100ms (valueList and dateList are just lists with doubles and dates):
If it's a timeseries chart:

Code: Select all

while (bottomPanel.realtimePanel.timeIndex.compareTo(vars.get(varIndex).calendarList.get(series.getItemCount())) >= 0) {
						series.addOrUpdate(new Millisecond(vars.get(varIndex).dateList.get(series.getItemCount())), vars.get(varIndex).valueList.get(series.getItemCount()));
						
						if (series.getItemCount() == vars.get(varIndex).calendarList.size())
							break;
					}
If it's a bar/dial chart (pretty much the same code):

Code: Select all

while (bottomPanel.realtimePanel.timeIndex.compareTo(vars.get(varIndex).calendarList.get(index)) >= 0) {
						datasetDegree.setValue(vars.get(varIndex).valueList.get(index));
						index++;
						
						if (index == vars.get(varIndex).calendarList.size()) {
							index--;
							break;
						}
					}
I am thinking this has to do with how values are aadded to TimeSeries.
Last edited by Siniz on Wed Sep 10, 2008 10:00 am, edited 1 time in total.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Sep 10, 2008 10:00 am

Are you adding multiple values to the time series chart? Each call to addOrUpdate() will trigger a DatasetChangeEvent that will, in turn, trigger a chart repaint. If you are adding multiple values, switch off chart event notification first (chart.setNotify(false)) then switch it back on when you're done updating the dataset (chart.setNotify(true) - this call will trigger the chart repaint that will show all the new values in your dataset).

Aside from that, each time a chart is updated the whole chart is repainted...so it is slower than it could be if JFreeChart had been designed with dynamic charts specifically in mind. Performance will be affected by lots of factors, including the dimensions of the chart(s), which version of the JRE you use (JRE 6.0 seemed to improve Java2D performance significantly), your hardware, whether or not you have antialiasing switched on for the charts, and lots of other things.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Post by Siniz » Wed Sep 10, 2008 10:03 am

I will try the setNotify thing. Are you certain there's nothing with sorting of the lists each time a new time/value is added to TimeSeries?

edit: Also, would DynamicTimeSeries help in any way?
edit2: I tried the notify thing but it's still slow. Changing the alias doesn't help much either.

Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Post by Siniz » Wed Sep 10, 2008 12:34 pm

Ok it seems like decreasing the charts sizes (by resizing the JFrame the charts are in) it goes significantly faster. Why is this?!

Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Post by Siniz » Wed Sep 17, 2008 10:17 am

Any clues :)?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Sep 18, 2008 2:44 pm

Java2D operations are generally faster on smaller sized surfaces, as far as I can tell...which makes sense I guess.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Siniz
Posts: 30
Joined: Mon Jul 21, 2008 10:38 am

Post by Siniz » Tue Sep 30, 2008 4:58 pm

Yes that is true. I am not sure however how that would relate to JFreeChart since JFreeChart doesn't really have a lot of graphics painted. I've done applications that use Java2D which is a lot faster, but with more stuff going on.

Do you have any other ideas what it could be David? I appreciate all help I can get. :)

gizza
Posts: 7
Joined: Tue Oct 14, 2008 8:25 am

vital sign graphs in a combined dynamic chart judder

Post by gizza » Wed Jan 14, 2009 6:01 am

Hi everyone,

I tried all your hack and ideas, but unfortunately they could not solve the problem.

My application has 5 vital sign graphs as a combined dynamic chart, which are updated every 100ms. The chart covers more or less the entire screen.

It is working, though one can notice some juddering in the chart movement, which is not acceptable, as it is a medical application.

Is there another framework, hack, or solution for a combined dynamic chart which could solve this problem? It does not have to be JFreeChart. Can anyone share some experience?!

Thanks a lot!

Chris

PS: Despite the problem I have, I really like the variety and adjustable properties JFreeChart offers.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Wed Jan 14, 2009 12:22 pm

It is pretty hard to diagnose performance problems without having access to the code to check exactly what you are doing. Have you run a profiler to see where JFreeChart is spending its time? Or written some log statements to check that JFreeChart is only repainting when you'd expect it to? There are so many dimensions to performance, I don't know what to suggest specifically. You can try things like switching off anti-aliasing (faster charts, but not as nice looking), ensuring that your dataset only retains visible data (anything that has scrolled off the screen isn't worth retaining in the live chart), check that tooltips aren't generated if you aren't using them, etc. etc.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

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

Post by paradoxoff » Wed Jan 14, 2009 10:46 pm

What if you wrap your original TimeSeriesCollection into an XYDataset implementation that only notifies the plot about every n-th addition of data and that only reports a subset of the data to the plot?

A second but more difficult approach: if you absolutely need every single data point, you could
- split the data area up into n blocks along the domain axis
- the blocks from n = 0 to n-2 contain old data that doesn´t need to be refreshed. These blocks could be drawn from a BuffferdImage
- the n-1 block contains data that is continuously updated. Only this block will have to be drawn "live"
- when the rightmost border of the plot is reached, i.e. when the n-1 block is full, the 0th block is thrown away, blocks 1 to n-2 are shifted one step to the left, block n-1 is saved as BufferedImage, and a new block is started (autoscroll by a defined increment).
You would of course have to intercept a lot of things like setting the domain axis range and zooming, so this is unlikely to be a short-term apporoach.

Locked