Combined plot: use same label for 2 series in diff subplots

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ge0ffrey
Posts: 20
Joined: Sat Feb 27, 2010 6:44 pm
antibot: No, of course not.

Combined plot: use same label for 2 series in diff subplots

Post by ge0ffrey » Tue Feb 10, 2015 1:10 pm

Hi,

I have a CombinedRangeXYPlot and I 'd like to use the same label in the legend for 2 series in different subplots.
Currently I get different labels (and so different colors) for the 2 series, despite that they represent the same domain object (machine in my case).

For the pseudo code below gives 6 labels, but I only want 3 (one for each machine):

Code: Select all

            OHLCSeriesCollection seriesCollection = new OHLCSeriesCollection();
            OHLCSeries machine1Series = new OHLCSeries("Machine 1");
            OHLCSeries machine2Series = new OHLCSeries("Machine 2");
            OHLCSeries machine3Series = new OHLCSeries("Machine 3");
            XYPlot plot = new XYPlot(seriesCollection, ...);

            XYSeriesCollection seriesCollectionB = new XYSeriesCollection();
            XYSeries machine1SeriesB = new XYSeries("Machine 1");
            XYSeries machine2SeriesB = new XYSeries("Machine 2");
            XYSeries machine3SeriesB = new XYSeries("Machine 3");
            XYPlot plotB = new XYPlot(seriesCollectionB, ...);

           CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(...);
           combinedPlot.add(plot, 5);
           combinedPlot.add(plotB, 1);

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Combined plot: use same label for 2 series in diff subpl

Post by paradoxoff » Thu Feb 12, 2015 1:54 pm

Frankly, I am a bit confused.
The legend entries should be identical. No idea, why this is apparently not the case. Can you give us the labels that appaear in the legend for the six entries?
Regarding the color: in order to get the same colors for the same machine, you will have to adjust the colors manually. By default, JFreeChart ensures that the series color in a plot are NOT identical.

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

Re: Combined plot: use same label for 2 series in diff subpl

Post by david.gilbert » Thu Feb 12, 2015 9:48 pm

In the CombinedRangeXYPlot class, take a look at the getLegendItems() method source code. You have two options:

- call the setFixedLegendItems() method and specify the legend items manually (this overrides the code that does the lookup in the subplots); or
- override the method an implement it so it returns the series from just one subplot (or any set of legend items that you want);
David Gilbert
JFreeChart Project Leader

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

Locked