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.
How to make JFreeChart support real-time charting?
-
- Posts: 6
- Joined: Mon Jan 26, 2009 2:12 pm
- Location: USA
- Contact:
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
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
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 47
- Joined: Thu Dec 11, 2008 7:59 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.
-
- Posts: 6
- Joined: Mon Jan 26, 2009 2:12 pm
- Location: USA
- Contact:
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.
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.
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
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
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Re: How to make JFreeChart support real-time charting?
i run the RealTimeXYScrollSeriesDemo example,it's useful for me,thank you!
Re: How to make JFreeChart support real-time charting?
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.
Re: How to make JFreeChart support real-time charting?
anyone have a newest url for jfreechart-1.0.12rt.zip?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.