How to make JFreeChart support real-time charting?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
taojiang_2000
Posts: 6
Joined: Mon Jan 26, 2009 2:12 pm
Location: USA
Contact:

How to make JFreeChart support real-time charting?

Post by taojiang_2000 » Mon Jan 26, 2009 10:24 pm

I found it is not very hard to get real-time capability in JFreeChart. I have successfully made a relatively small change to get it work. The performance problem in JFreeChart is that it completely repaints chart for each update, including, chart border, title, Axis, etc. Of course, tons of overhead. My approach is very simple:
1. Actually, for any real time point, only the latest point should be repainted if we let JFreeChart to use buffer for drawing.
2. Create RealTimeXYDataset by subclassing AbstractXYDataset and do:
2.1 Create a ring buffer to hold all realtime data during the displaying period.
2.2 Override the getItemCount() and let it return 2 to tell the JFreeChart only redraw the last two points during normal case and let it return the size of ring buffer when chart is resized, or anything needs total repaint and switch back to 2 thereafter.
2.3 Override getX() and getY() accordingly.
3. Modify the method draw() inside class JFreeChart add logic to paint chart border, title, etc when necessary.

The same principle can be applied to other chart types. I really like this feature to be in the JFreeChart's future release.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Tue Jan 27, 2009 1:38 am

Could you provide a compilable demo? It is hard to test the functionality, performance, and pitfalls of this approach without seeing the relevant source and a demo. You could upload the source code to the patch tracker and post a link here.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

MitchBuell
Posts: 47
Joined: Thu Dec 11, 2008 7:59 pm

Post by MitchBuell » Tue Jan 27, 2009 5:21 pm

I am extremely interested in a working copy as well. I wish to create a real time chart class that the user will eventually have LOTS of. Up to nearly 100 little JFreeCharts on a single JPanel. They will only be updated at a max of once a second. And obviously each little JFreeChart redrawing itself on new data is a huge CPU hog.

taojiang_2000
Posts: 6
Joined: Mon Jan 26, 2009 2:12 pm
Location: USA
Contact:

Post by taojiang_2000 » Wed Jan 28, 2009 5:22 am

I have done that a little over a year ago based on jfreechart-1.0.7. I have uploaded a modified version along with a demo program into:
googlepages. (well, the system doesn't allow me to post url, I will use dot for "." and slash for "/")

tjiang2000 dot googlepages dot com slash jfreechart-1.0.7.zip

You can figure out what I have done by comparing it with original jfreechart-1.0.7. go to org.jfree.chart.demo folder. I have created the following files:
1. IDataSource.java: to generate random value to feed the chart.
2. IRealTimeDataSet.java: interface for adding realtime parameters.
3. RealTimeXYDataset.java: a dataset for handling realtime data.
4. FastChartPanel.java: modified version for ChartPanel.java. I might need to just modify the ChartPanel.java directly instead.
5. RealTimeXYSeriesDemo2.java: a demo program.

The demo program might be a little buggy because I didn't have enough time. The chart draws very quickly and you can resize the chart window a little bit to clean the old drawing. I also figured out how to make a realtime scrolling plot but it is not in the demo.

Just want to get idea across. If this is a feasible approach, we can figure out how to get it into the jfreechart release.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Wed Jan 28, 2009 6:49 pm

Cross-referencing XY charts - dynamic data, drawing updated area only since the thread discusses another possible fast, dynamic, updating method (and provides code).
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

maswjxh
Posts: 5
Joined: Thu Jul 30, 2009 7:06 am
antibot: No, of course not.

Re: How to make JFreeChart support real-time charting?

Post by maswjxh » Thu Jul 30, 2009 7:17 am

i run the RealTimeXYScrollSeriesDemo example,it's useful for me,thank you!

maswjxh
Posts: 5
Joined: Thu Jul 30, 2009 7:06 am
antibot: No, of course not.

Re: How to make JFreeChart support real-time charting?

Post by maswjxh » Sun Aug 02, 2009 8:24 am

i have download the "jfreechart-1.0.12rt.zip" and compile it, then i run the demo example,but i found a little question,when i clicked the mouse,the chartpanel refresh and only redraw the new point. the older point not redraw. what happened? But I run the "rt_scroll_demo.jnlp" example, i haven't found this problem.

shilei
Posts: 4
Joined: Wed Dec 01, 2010 5:57 am
antibot: No, of course not.

Re: How to make JFreeChart support real-time charting?

Post by shilei » Sun Dec 26, 2010 2:51 pm

maswjxh wrote:i have download the "jfreechart-1.0.12rt.zip" and compile it, then i run the demo example,but i found a little question,when i clicked the mouse,the chartpanel refresh and only redraw the new point. the older point not redraw. what happened? But I run the "rt_scroll_demo.jnlp" example, i haven't found this problem.
anyone have a newest url for jfreechart-1.0.12rt.zip?

Locked