Colors for multiple series in TimeSeriesCollection

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
JGoodwin
Posts: 27
Joined: Thu Sep 06, 2007 3:19 am
Location: Boston USA

Colors for multiple series in TimeSeriesCollection

Post by JGoodwin » Thu Jun 26, 2008 6:59 pm

Hello,

In the User's Guide 13.2.5 it says that when you add an additional dataset,
"...if you don’t specify an additional renderer, the primary renderer will be used instead. In that case, the series colors will be shared between the primary dataset and the additional dataset."

Doesn't seem to work for me: I get red on both series.
Using jcommon-1.0.10.jar and jfreechart-1.0.6.jar, jre 1.6.0_05

Code fragments:

// First dataset
TimeSeriesCollection tsc = new TimeSeriesCollection();
tsc.addSeries(priceIndexSeries);
plot.setDataset(0, tsc);

// Axis 0 is automatically provided but fix its label
plot.getRangeAxis(0).setLabel("Cluster Price Index");

// Second dataset
tsc = new TimeSeriesCollection();
tsc.addSeries(coherenceSeries);
plot.setDataset(1, tsc);

// Create and assign an axis to it explicitly.
NumberAxis axis1 = new NumberAxis("Cluster Coherence");
plot.setRangeAxis(1, axis1);
plot.mapDatasetToRangeAxis(1, 1);

Any idea what I'm missing?
Thanks
Jim

prassoon
Posts: 14
Joined: Fri May 23, 2008 1:57 am

Post by prassoon » Thu Jun 26, 2008 10:18 pm

I'm not sure whether I understand you well...but I recently get through some coloring issues... you may check this thread, may be it helps

http://www.jfree.org/phpBB2/viewtopic.p ... ght=#70429

dan1son
Posts: 12
Joined: Thu Jun 29, 2006 7:06 pm
Location: Austin, TX

Post by dan1son » Tue Oct 14, 2008 10:31 pm

Anyone have a good solution to this problem?

I'm making simple TimeSeriesCollections with one or more datasets each and assigning each of those to their own Range Axis on a TimeSeriesChart. Doing that causes the colors to start over for each TimeSeriesCollection, which is against what the developers guide says.

My main issue is I don't know how many series there will be until creating the chart so I can not manually color them. I've tried manually forcing the same renderer on each DataSet with the same results. I need a way to have an arbitrary number of colors (one per series) for an arbitrary number of ranges axis.

Any help is appreciated,
Dan

EDIT: As a further note, the current MultipleAxisDemo2 and 3 show all red lines. Is this issue a bug in the current version?

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 » Wed Oct 15, 2008 8:45 am

I think the explanation in the developer guide isn't clear enough. If you have multiple datasets but just one renderer, the series colours assigned to the renderer will be *repeated* for each dataset (e.g. if the renderer is using Color.RED for series 1, it will apply that to series 1 in dataset 1 *and* to series 1 in dataset 2).

The solution is to add a separate renderer for each dataset...then the additional renderer will obtain its own set of colours (and the DrawingSupplier for the plot should ensure that these are unique, if you rely on the auto populate mechanism).

I think it is possible that this may have worked differently in some prior version, but I'd have to go back and check that.

Thanks for spotting the bug in MultipleAxisDemo2 and 3 - I'll fix those (by adding a second renderer in the demo code).
David Gilbert
JFreeChart Project Leader

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

dan1son
Posts: 12
Joined: Thu Jun 29, 2006 7:06 pm
Location: Austin, TX

Post by dan1son » Wed Oct 15, 2008 4:35 pm

David,

Assigning a new renderer to each dataset did do what I wanted. The colors are now all unique.

Thank you,
Dan

Locked