I'd like to share my progress so far and compare notes. I found this example
which demonstrates how this can be done using a TimeTableXYDataset
. I don't like that TimeTableXYDataset uses a TimePeriod
to represent the time, but I was able to modify
it to use a SimpleTimePeriod
based on a long (e.g. the current step). I don't see a way to base a TimePeriod on a double since the interface returns Date objects. One option would be to write a sibling class of TimeTableXYDataset that uses doubles instead of TimePeriods but I's prefer to use only the standard JFreeChart classes if possible.
Option A) Version
based on TimeTableXYDataset.
- Uses TimePeriods, which are heavier than necessary and based on Dates rather than doubles
- Stores data internally with DefaultKeyedValues2D rather than individual XYSeries
I also tried:
- Uses individual XYSeries
- Can use doubles for the time values
- Doesn't work!
- DefaultTableXYDataset is a lot heavier than necessary because it doesn't assume you're adding data in order
Here's what happens: DefaultTableXYDataset listens to the change event for all the XYSeries you add to it. Whenever you add a value to any series with a previously unseen x-value (e.g. x=1), it adds a dummy entry to all the other series. Then, when you try to add a value (at x=1) to another series, it sees the dummy value already there (at x=1) and throws a SeriesException: X-value already exists.
I'm not sure if this is the intended behavior or a bug. Seems like a bug to me.
I also tried turning off the notifications, but then it never draws anything. I tried forcing an update through the dataset and the chart but neither approach worked.