Stacked XYStepArea - is it possible?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rade
Posts: 7
Joined: Thu Dec 11, 2008 4:37 pm

Stacked XYStepArea - is it possible?

Post by rade » Thu Dec 11, 2008 4:52 pm

Hello!

I use TimeTableXYDataset as a dataset (x-axis values are Dates, and it should be stacked) and XYStepAreaRenderer.

Problem is I don't know how to render these series in stacked way.

As far I understand it, a XYPlot can have only one renderer per dataset.
So, I don't know how to use StackedXYAreaRenderer together with XYStepAreaRenderer...

Thanx :)

rade
Posts: 7
Joined: Thu Dec 11, 2008 4:37 pm

Post by rade » Mon Dec 15, 2008 3:06 pm

Does anybody have an idea how this can be done?

I'm trying with TimeSeriesCollection, TimePeriodValuesCollection, SegmentedTimeline...

Any hints? :)

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Dec 15, 2008 3:13 pm

There isn't a version of XYStepAreaRenderer that handles stacked values.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

rade
Posts: 7
Joined: Thu Dec 11, 2008 4:37 pm

Post by rade » Mon Dec 15, 2008 3:19 pm

I realized that, but I believe there have to be a way to do this...

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Mon Dec 15, 2008 3:25 pm

rade wrote:I realized that, but I believe there have to be a way to do this...
There is...you need to take the XYStepAreaRenderer and modify it so that it can handle stacked values. Most of the renderers that exist in JFreeChart came about because someone wanted a way to draw data that wasn't already handled by JFreeChart.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

jleech
Posts: 62
Joined: Fri Oct 26, 2007 9:18 pm

Post by jleech » Mon Dec 15, 2008 7:09 pm

Hi,

I do exactly what you're asking about using a TimeTableXYDataset and XYStepAreaRenderer. If your data is sparse, you have to fill in all the values for each time point / data series. Then you just fake the stacking by adding up each of the previous series values at each time point; e.g.
1 2 3 (Series)
----------
1 2 1 (Values)

becomes

1 2 3 (Series)
----------
1 3 4 (Values)

Of course you could also subclass it to do the same thing but its pretty straightforward to just change the data.

rade
Posts: 7
Joined: Thu Dec 11, 2008 4:37 pm

Post by rade » Tue Dec 16, 2008 2:02 pm

jleech wrote:If your data is sparse, you have to fill in all the values for each time point / data series.
This is exactly how I planned to do it...

It basically means that before actual graph rendering you must:
1. loop through all the data and get each distinct x-value
2. pre-calculate y-values for each x-value
And than you render the graph with XYStepAreaRenderer.

But it seems that this approach has two deficiencies:
- area for each step is rendered from the bottom (baseline), but only part of it that is above all the other areas is visible - this probably adds some overhead
- you actually modify the data instead of letting the renderer to do it's job (as david.gilbert proposed)


But nevertheless, it seems to be a faster solution than modifying the XYStepAreaRenderer...

nono
Posts: 2
Joined: Wed Jan 07, 2009 4:15 pm

Post by nono » Fri Jan 09, 2009 9:44 pm

Hello,

I have the same problem.
Do you find a good solution or the only solution is to modify the data ?

Thanks.

Locked