A quick question about JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
Posts: 2
Joined: Thu Jul 12, 2018 9:03 am
antibot: No, of course not.

A quick question about JFreeChart

Post by rosabella » Thu Jul 12, 2018 9:32 am

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.

Post Reply