Print

Print


I'd like to share my progress so far and compare notes. I found this example
<http://stackoverflow.com/questions/16772698/dynamic-time-series-stacked-area-chart-in-java>
which
demonstrates how this can be done using a TimeTableXYDataset
<http://www.jfree.org/jfreechart/api/javadoc/org/jfree/data/time/TimeTableXYDataset.html>
and ChartFactory.createStackedXYAreaChart(...)
<http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/ChartFactory.html#createStackedXYAreaChart-java.lang.String-java.lang.String-java.lang.String-org.jfree.data.xy.TableXYDataset->.
I don't like that TimeTableXYDataset uses a TimePeriod
<http://www.jfree.org/jfreechart/api/javadoc/org/jfree/data/time/TimePeriod.html>
to
represent the time, but I was able to modify <http://pastebin.com/Ek5MxyNf> it
to use a SimpleTimePeriod
<http://www.jfree.org/jfreechart/api/javadoc/org/jfree/data/time/SimpleTimePeriod.html>
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 <http://pastebin.com/Ek5MxyNf> based on
TimeTableXYDataset.
Pros:
- Works

Cons:
- 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:
Option B) Version <http://pastebin.com/piDHwP0N> that uses a
DefaultTableXYDataset
<http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/data/xy/DefaultTableXYDataset.html>
to
store the data.
Pros:
- Uses individual XYSeries
- Can use doubles for the time values
Cons:
- 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.

Thoughts?

Joey


On Fri, Jun 10, 2016 at 2:35 PM, Sean Luke <[log in to unmask]> wrote:

> I'm not aware of it.
>
> I thought there might be two ways go about this: (1) treat each stacked
> row as a separate series and (2) assume that the series has data for all
> the rows together -- like an array or a list of numbers.  It turns out #1
> isn't possible in JFreeChart.
>
> Sean
>
> On Jun 10, 2016, at 7:56 PM, Joseph F Harrison <[log in to unmask]> wrote:
>
> > I'm looking to make a stacked area time series chart a bit like this,
> and I'd like to do it within the MASON *ChartGenerator framework. Has
> anyone done this already?
> >
> > Joey
>