23 second to recreate a chart with 3000 samples with JfreeChart

E

etantonio

Hi,
I'm creating an application that displays in charts data coming from
the com port,
for the charts I use Jfreechart , all seems to work but in my
application I've several charts,
so when I change from one to the other I recreate the serie from a
storage,
in this storage I've an arraylist of StringAndTime objects, a string
that represents the bytes coming from the serial port and a
Millisecond element tipycal of JFreeChart.
My problem is that I need lower times to switch from one chart to the
other, this is about 23 second to recreate a chart with 3000 samples,
how I can achieve this by your point of view ?

Thanks

Antonio
ww.etantonio.it/en
 
N

Nigel Wade

etantonio said:
Hi,
I'm creating an application that displays in charts data coming from
the com port,
for the charts I use Jfreechart , all seems to work but in my
application I've several charts,
so when I change from one to the other I recreate the serie from a
storage,
in this storage I've an arraylist of StringAndTime objects, a string
that represents the bytes coming from the serial port and a
Millisecond element tipycal of JFreeChart.
My problem is that I need lower times to switch from one chart to the
other, this is about 23 second to recreate a chart with 3000 samples,
how I can achieve this by your point of view ?

You really need to determine where within your program that time is being spent.
Unless you know that you cannot effectively optimize the program.

My guess would be that much of the time is taken in converting from the String
objects which represent the incoming data, into a form which JFreeChart can
display. Try running some tests to determine whether this is the case. Time how
long it takes to convert the String data to whatever data format JFreeChart
uses, and how long it takes to redraw the plot of this data. If the conversion
time is causing the delay then store the converted data rather than the
Strings, if it's JFreeChart which takes a long time to draw the plot then you
may be out of luck.
 
J

John B. Matthews

etantonio said:
I'm creating an application that displays in charts data coming from
the com port, for the charts I use Jfreechart , all seems to work but
in my application I've several charts, so when I change from one to
the other I recreate the serie from a storage, in this storage I've
an arraylist of StringAndTime objects, a string that represents the
bytes coming from the serial port and a Millisecond element tipycal
of JFreeChart. My problem is that I need lower times to switch from
one chart to the other, this is about 23 second to recreate a chart
with 3000 samples, how I can achieve this by your point of view ?

With MAX = 3000 and two series totaling 6000 points, this example never
takes more than a second or two to update, even at higher resolutions:

<http://sites.google.com/site/drjohnbmatthews/jfreechartdemo>

You'll need to profile your code, but I doubt rendering is the
bottleneck. Three thousand points is rather a lot to digest; you might
look into zooming, which is automatic with ChartFactory, or scrolling.

An example might help.
 
N

neuneudr

Hi,
I'm creating an application that displays in charts data coming from
the com port,
for the charts I use Jfreechart , all seems to work but in my
application I've several charts,

I'm using JFreeChart to plot huge data (graph representing data
with a few hundred thousands to millions of entries).

JFreeChart has serious performances issues (and it is a memory pig)
but
3000 samples is really not much. 23 seconds is crazy.

Note that if you're only adding, say, 5 entries and recomputing a
graph that has 99 995 common entries with the previous graph, then
JFreeChart is not a suitable API. This has been debated ad nauseam
on the JFreeChart forums and several people simply dumped the
JFreeChart API. The main author wrote himself in a post that
JFreeChart was not the best option for such tasks (remember that
in addition to be painfully slow it is also a memory pig [the
two being related for sure]).

To plot so many data we're pre-processing that data ourself and
only presenting a few thousands entries to JFreeChart (instead
of hundreds thousands/millions) (what's the point in sending
millions of (X,Y) plots to a bloated graphing API when it shall
produce a graph at max 1000 pixels wide ;)

In the end we plan on switching to a charting API more suited
to our need (real-time updating graph where new entries are
always appended at the end) or writing the graphing components
we need ourselves (we don't need all the fancy JFreeChart bells
and whistles, just fast, responsive, memory-conscious, realtime
updating graph).

But, yup, if your 3 000 isn't a typo you're doing something
wrong.
 
R

Roedy Green

I'm creating an application that displays in charts data coming from
the com port,
for the charts I use Jfreechart , all seems to work but in my
application I've several charts,
so when I change from one to the other I recreate the serie from a
storage,
in this storage I've an arraylist of StringAndTime objects, a string
that represents the bytes coming from the serial port and a
Millisecond element tipycal of JFreeChart.
My problem is that I need lower times to switch from one chart to the
other, this is about 23 second to recreate a chart with 3000 samples,
how I can achieve this by your point of view ?

Some possibilities:

1. look into other charting packages. Something else might be faster.
see http://mindprod.com/jgloss/graph.html

2. Consider painting the new chart to an offscreen buffer, and only
when it is ready blast it to the screen on top of what was previously
there.

3. You suggested that data was travelling over some slow serial port.
Perhaps it could be compressed, or predigested to be more compact.
Perhaps you can use a faster port e.g. USB 2, or Ethernet.

4. try the program on another machine with a relatively expensive
video card to rule out a bottleneck with the video driver or hardware.

Your first task is to figure out where the bottleneck is. You need to
figure out how to run your program to eliminate the possible
bottlenecks by simply not doing the work and seeing if the program
greatly speeds up.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Perfect reusable components are not obtained at the first shot."
~ Bertrand Meyer (born: 1950 age: 59) 1989, creator of design by contract and the Eiffel language.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top