100% CPU usage problem

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
cassidyh
Posts: 10
Joined: Mon Jun 27, 2005 1:19 pm
Location: MD
Contact:

100% CPU usage problem

Post by cassidyh » Thu Jun 30, 2005 12:40 pm

HI,
I am trying to continuously update 4 XYBarcharts within a panel, but as soon as I start the plotting, my CPU usage jumps to 100%. AM I overlooking something?Anyone with any suggestions, I would appreciate any help
Cassidy

rickbier
Posts: 3
Joined: Fri Jun 24, 2005 2:48 pm
Location: Saint Louis

Heavy load

Post by rickbier » Thu Jun 30, 2005 9:31 pm

I found the same thing in using the plotting package. I found it best to lower the priority of the program doing the plotting so other tasks could get some CPU time.

cassidyh
Posts: 10
Joined: Mon Jun 27, 2005 1:19 pm
Location: MD
Contact:

CPU time issue

Post by cassidyh » Fri Jul 01, 2005 12:50 pm

Hi
I found the bug that caused my bottleneck. I was processing all data in my incoming, including 0s. SO everytime I added data to my series, I also added zeros. Once I put in a simple if(data!=0){ series.add(data)} all my problems have also disappeared. You might want to also check for something so simple as that for getting CPU performance up.
Cass

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 » Fri Jul 01, 2005 1:38 pm

If you are adding multiple new values to a dataset, be aware that each 'add' will trigger a DatasetChangeEvent and repaint the chart. You can avoid that by using this approach:

Code: Select all

chart.setNotify(false);
// do multiple dataset updates here
chart.setNotify(true);
The same applies to any other changes you make to the chart, plot(s), axes, renderers, titles etc.
David Gilbert
JFreeChart Project Leader

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

rickbier
Posts: 3
Joined: Fri Jun 24, 2005 2:48 pm
Location: Saint Louis

To speed up points added to series

Post by rickbier » Fri Jul 01, 2005 2:40 pm

Taking a hint from another post to your message, I found that when adding points to a series (which I do before creating the chart), the following speeds things up by a factor of 4:

XYSeries s1 = new XYSeries(...);
s1.setNotify(false);
add all points to the series
s1.setNotify(true);

cassidyh
Posts: 10
Joined: Mon Jun 27, 2005 1:19 pm
Location: MD
Contact:

CPU

Post by cassidyh » Fri Jul 01, 2005 2:50 pm

Thanks a lot,
I tried the setnotify, and it seems to be working fine. I also had to make sure to call the series.clear() before updating the chart

Locked