How can I use JFreeChart
to display just the most recent data in a continually updated time series?
Addenda: A complete, working example that incorporates the accepted answer is shown here. See also this variation having two series. See also this Q&A regarding setTimeBase()
.
One alternative approach to @thrashgod's answer would be to use
TimeSeriesCollection
and setting item age on theTimeSeries
. Below code can setup a graph to show last 1 hour of data with 1 minute intervals...and you will add the data as it comes with:
The
JFreeChart
classDynamicTimeSeriesCollection
is a good choice.Addendum: As noted by @Bahadır, the last point of the series was persistently zero. @Don helpfully suggests advancing the time and then appending the data.
You can also eliminate the zero by first advanceTime(), then appendData. (swap the way they are doing it in the example).