Hi,
I am trying to create a dynamic timeseries chart. The domain axis of this chart will plot items for every second. I am initializing my BasicTimeSeries object by saying
series = new BasicTimeSeries ( "", Second.class );
Now, I require that the domain axis, at any given time, display values over the last one hour only. To achieve this, I do
HorizontalDateAxis axis = ( HorizontalDateAxis ) plot.getDomainAxis ();
axis.setAutoRange ( true );
axis.setFixedAutoRange ( 60 * 60 ); // Representing one hour in seconds
This does not work as I expected. I realized I must set the range with millisecond granularity. So I should do
// Representing one hour in milliseconds
axis.setFixedAutoRange ( 60 * 60 * 1000 );
I thought that since my series object is aware of the "second" granularity, the range of the axis should be declared with "second" granularity, not "millisecond".
I did check the javadoc, but only found "Sets the fixed auto range for the axis." under the description of setFixedAutoRange ().
Where am I going wrong? I am new to jfreechart, so your help will be deeply appreciated.
Thanks,
Alan
How to specify timeseries granularity
Re: How to specify timeseries granularity
Hi Alan,
The axis works with milliseconds, and doesn't really know anything about the dataset except what it can find out via the XYDataset interface (so it doesn't know that your time series is using seconds).
Note that the fixed auto range only affects the axis range, it doesn't change your dataset at all (all the old data is retained).
A better option for you might be the setHistoryCount(...) method in the BasicTimeSeries class. This specifies a fixed period of time (you would specify 60 * 60 for your example) - when a new data item is added, anything older than the specified number of periods is automatically dropped from the series.
Regards,
DG
The axis works with milliseconds, and doesn't really know anything about the dataset except what it can find out via the XYDataset interface (so it doesn't know that your time series is using seconds).
Note that the fixed auto range only affects the axis range, it doesn't change your dataset at all (all the old data is retained).
A better option for you might be the setHistoryCount(...) method in the BasicTimeSeries class. This specifies a fixed period of time (you would specify 60 * 60 for your example) - when a new data item is added, anything older than the specified number of periods is automatically dropped from the series.
Regards,
DG
Re: How to specify timeseries granularity
Thanks for your reply David. I was wondering if the setHistoryCount function you mentioned has been added in the 0.9.4 version. I am running 0.9.3 and could not find this function in my IDE. In any case, thats not a biggie since I will upgrade to 0.9.4