Dynamic chart

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

Dynamic chart

Post by Girish Managoli » Thu Jul 26, 2001 1:29 pm

Hello,

I am trying to generate dynamic chart the following way.
I have written an own impl of XYDataSource. As and when
new data is recd, I put the data into my internal structures
of MyXYDataSource and call chart.setDataSource(dataSource).
This does the trick, and the chart appears to move.

This is fine but a question and a problem:

1. Initially when I create a chart, no data is available.
The chart gets updated only when a new data is received.
It was not possible to create an 'empty' chart. The chart
just hangs if I create chart with a data source that returns
'0' for getItemCount(). Is is really not possible to create
the "empty" chart?

2. I used this workaround: When I see there is no data,
I return 1 for getItemCount() and values 0 for getXValue()
and getYValue(). The chart is created, but when it is time
to update with new data, everything goes hayware. As soon
as I call setDataSource(), my CPU usage shoots upto 100%,
windows stop responding, and after a few minutes, the java
console start printing exception message like hell, which
I cannot makeout anything (cannot see, cannot copy). Any
idea why this could be?
However if I do not have the workaround, ie, I just create
dummy 0 value in the beginning and start updating the values
as and when they come, I get a beautiful moving graph.

3. Is there any other way to create dynamic graphs?

I am running the graph thro an applet on Win2k with IE.
I will supply any other details required.

One word I should mention here, it is a very good package,
JFreeChart, we have here. Worth the praise & worth the price(!)

Thanks and regards,
Girish.

David Gilbert

RE: Dynamic chart

Post by David Gilbert » Thu Jul 26, 2001 8:25 pm

Hi Girish,

Thanks for your posting. Dynamically updating charts is not 100% complete in JFreeChart yet, as you've discovered.

The intention is that you should only have to call chart.setDataSource(...) once. After that, when you change your datasource, all you need to do is notify all the registered listeners (the chart should be one of these) by calling the dataSourceChanged(...) method for each registered listener. The chart should respond to this by redrawing itself.

The data sources that I've implemented so far don't include any methods for modifying the data, so they are not dynamic. Some time I'll get around to changing DefaultXYDataSource so that you can modify the data, but it is not top priority for me...in any case, it's better to implement the XYDataSource around your own data structures as you have done.

It is a bug that you cannot have zero series in your data source. This will get fixed soon. You should also be able to set the datasource to null, but this fails in version 0.5.6 also (but is fixed in the latest source code which you can download via CVS from SourceForge).

A few developers have asked me about applets and JFreeChart - I'm no applet expert, but it sounds like you've mastered this. If you want to post some hints about JFreeChart and applets, I'd appreciate it a lot and I'm sure others will also.

Last of all, thanks for your comments/praise...it's always good to hear when people like JFreeChart

Regards,

DG.

Locked