Sunday, February 1, 2009

How to make JFreeChart support realtime charting?

JFreeChart is probably the best Java chart library I have ever used. It has lots of excellent features. Unfortunately, it doesn't support realtime charting. In many cases, Real-time charting is a very important feature to have. For example, my previous data acquisition project needs data refreshing rate at least 10 times per second. It is also very important for any financial chart, for example: intra-day stock chart.

Well, it is not that 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. User tends to simply add point into the dataset whenever a new point is available. This causes JFreeChart redraw all those points. The idea is very simple: Just let JFreeChart to use buffer to draw point incrementally. For any real time point, only the draw the latest points (2 points).

I have posted a detailed description along with demo source code at JFreeChart

1 comment:

  1. How do I get the values from a Postgres Database? Are the JDBC***** datatype supported by the Postgres Database?