Reputation: 881
I'm in the process of creating a chart that shows the data over a period of time for a sim run. The problem I'm running into is I don't seem to be able to use TimeSeriesCollection as it uses a date object that starts at Jan 1 1970. The date formatting we are requiring is one that counts upwards from the simulation start time.
For instance, if an event happened that causes the count to increase at the 60 minute mark of the simulation, the time stamp on the chart would read 01:00:00 (one hour, zero minutes, zero seconds). If an event happened at the 28th hour, 19th minute, 12 second, the timestamp along the X axis would need to read 29:19:12.
The data I'm plotting is simply ints over time.
Anyone able to give me a quick and dirty rundown of how I'm able to do this?
EDIT: I should state there is no requirement for me to use TimeSeriesCollection. I can use any and all utilities in the JFreeChart library.
Upvotes: 0
Views: 1211
Reputation: 4477
The RelativeDateFormat class is designed for exactly this purpose. Your data doesn't need to change (it is correct as-is), just the presentation needs to be adapted. So create an instance of RelativeDateFormat, passing it the start time of your simulation, and use this as the date formatter for your axis. It will display times relative to the start time.
Upvotes: 2
Reputation: 205785
As shown here, "The factory method ChartFactory.createTimeSeriesChart()
will accept any XYDataset
in which the domain represents milliseconds from the Java epoch." The example cited extends AbstractXYDataset()
; you can return the time stamps from your implementation of getX()
and your integers from getY()
.
Upvotes: 1
Reputation: 1717
I don't know the details of TimeSeriesCollection and JFreeChart, however you could probably solve your problem by storing the time the simulation starts, which is also relative to January 1, 1970:
long startTime = new Date().getTime();
You could then subtract the startTime value from the times in the TimeSeriesCollection to get your X axis values.
Upvotes: 0