posted 13 years ago
I suspect you don't actually want a new plot every 5 minutes. It is more normal to have a running plot where the X axis always displays the values from the last 5 minutes with the axis being update every second or so. To achieve this one needs to create an initially empty model that only store the values from the last 5 minutes and then, using a Swing timer, update the model every second or so by adding new values and and removing values more than 5 minutes old.
Using JFreeChart this is achieved by using a TimeSeries as the model and using the method setMaximumItemAge() to define how long the collection period is. In your case 5 minutes. Each time you add a new point to the TimeSeries using the timeseries.addOrUpdate() method points more than 5 minutes old will automatically be discarded. When you add a new point to the model you will need to set the display period to the last 5 minutes. This is simple if you use DateAxis for the X axis by using something along the lines of
Using this I tend to update the date axis more frequently than I update the model (typically 10 times a second) since then the axis flows rather than jerks across the screen but since your collection period is so large I doubt if this matters.
There is no need to explicitly fire any events. All updates of the model and X axis fire appropriate events. Sometimes I find this annoying because I often want to delay firing events until I have made a set of changes but what the heck - it is very very good and free.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.