Scrolling plot is a special plot with x axis parameter whose value always increases. For example, time series chart. Making a scrolling plot using JFreeChart is fairly easy because you can set a value range for the x axis and setAutoRange to true. Also, setup the how much you want the plot to scroll when the range out of range. For example:
ValueAxis xaxis = new NumberAxis();
xaxis.setRange(0, 100);
xaxis.setAutoRange(true);
xaxis.setFixedAutoRange(100);
// Note: when axis is set to use fixed auto range, the
// margin value is not used in JFreeChart. Here, we borrow
// the variable to let plot to shifting buffer.
xaxis.setLowerMargin(0.1); // 10% margin
xaxis.setUpperMargin(0.1);
Then, periodically watch the value on x axis and adjust the range accordingly. I have modified jfreechart-1.0.12 by adding real time plotting capability and created examples for both realtime xy plot and scrolling plot under the org.jfree.chart.demo. You can give the updated package jfreechart-1.0.12rt.zip a try. You can also check the similar post I made at jfree forum to follow the discussion.
The demos are bare minimal. Since Jfreechart is very powerful, you can add some decorated pieces, such as: grid, background image, etc fancy stuff for fun and also verify there shouldn't have any noticeable performance deterioration.
Showing posts with label JFreeChart. Show all posts
Showing posts with label JFreeChart. Show all posts
Sunday, February 22, 2009
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
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
Subscribe to:
Posts (Atom)
