Reputation: 57
I'm working on a dynamic chart with JfreeChart to display temperature recorded by an oven. Theses values are recorded every 2s and stored in a database which I then fetch to display it on my dynamic chart. The oven is always running and the goal is being able to see if any spike in temperatures occur (note that there's actually multiple oven).
I mostly inspired my work around Trashgod response here and there or other ones about that topic.
Here's a simplified version of my code :
public test(final String title) {
super(title);
final DynamicTimeSeriesCollection dataset =
new DynamicTimeSeriesCollection(3, 10, new Second()); // 1
dataset.setTimeBase(new Second(new Date()));
[...]
private JFreeChart createChart(final XYDataset dataset) {
final JFreeChart result = ChartFactory.createTimeSeriesChart(
TITLE, "hh:mm:ss", "°C", dataset, true, true, false);
final XYPlot plot = result.getXYPlot();
ValueAxis domain = plot.getDomainAxis();
domain.setAutoRange(true);
ValueAxis range = plot.getRangeAxis();
range.setRange(-MINMAX, MINMAX);
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setFixedAutoRange(10000); // 2
return result;
}
Now, I actually have several points that I don't manage to understand. First of all as described in the documentation
public DynamicTimeSeriesCollection(int nSeries,int nMoments,RegularTimePeriod timeSample) Parameters: nSeries - the number of series, nMoments - the number of items per series, timeSample - a time period sample.
The problem is that when I put nMoments as 10 like in my code, the time displayed is good meaning it's really close to the actual time also displayed on my computer but I'm quite far from the 2 days period that I want to monitor as it only show me the last 10 items. But when I increase nMoments (the number of items per series) the time shown isn't the "real" one and if I increase it too much it doesn't even load.
I just want to be able to have a DateAxis long enough so I can see the values I got up to 2 days ago but in a dynamic way (a FIFO with a 2 days period) but I also need the DateAxis to be accurate enough.
I mostly played with the value in //1 and //2 but I can't make it work like I want to and I'm out of ideas on how I'm supposed to use both. I managed to set //2 so that I have a range of 2 days but then the data was still in FIFO of 10 items and as I said, I have the impression that the time isn't right when I increase this limit.
I also thought about using TimeSeriesCollection but I didn't manage to use it correctly to make something work. Do I need to dig deeper in this or can I achieve what I want with DynamicTimeSeriesCollection ?
Any help would be greatly appreciated.
Upvotes: 1
Views: 230
Reputation: 57
I solved my problem by using TimeSeriesCollection
instead of DynamicTimeSeriesCollection
as mentionned by Trashgod in the comment. Using this post Real-time graphing in Java as an example.
Upvotes: 1