Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
How do I stop the colour of a series 2 changing when I make Series 1 not visible
posted

Hi

I have a chart (either column or line) that can have multiple series in. I give the use the ability hide each series if they choose but I want the colour that is used on initial viewing to be fixed for that line, even when they hide an earlier series. Currently if I have 3 seaparate series being viewed and they are coloured as follows:

1. Blue, 2. Red, 3 Green

If I make Series 1 invisible then the colouring changes to:

1. Invisible, 2. Blue, 3. Red

Is there a way to fix the colours and stop it chaning the colours? Do I have to manually fix the colours myself using ChartDrawItem event?

I have tried this and I can get it to work but...when I try colouring the legend I have to use Column and Row number to identify each series and obviously the column and row number changes when I make a series invisible. This means that currently my bars in my chart are staying the correct colour but the legend colouring is changing.

I can come up with some way to keep a mapping when a series is made invisible but I was just hoping there was a better way. If I could ientify the series label in ChartDrawItem when the legend is being drawn that would fix it but this doesnt seem to be available.

Any help much appreciated.

Tks

Dan

  • 7305
    posted

    You should be able to maintain the colors after removing or hiding one of the serieses if you set them like the following. This was tested on a Line chart.

    ser1 = new NumericSeries();
                ser1.Label = "Series-1";
                ser1.PEs.Add(new PaintElement(Color.Red));

    ser2 = new NumericSeries();
                ser2.Label = "Series-2";
                ser2.PEs.Add(new PaintElement(Color.Green));

    ser3 = new NumericSeries();
                ser3.Label = "Series-3";
                ser3.PEs.Add(new PaintElement(Color.Blue));