Cycling colors with more than 20 series?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Freddie
Newbie
Newbie
Posts: 13
Joined: Thu Jun 25, 2009 12:00 am

Cycling colors with more than 20 series?

Post by Freddie » Fri Mar 19, 2010 5:39 pm

Hi,

I am using the WPF library and I am creating a number of series in my Tchart.
I am creating a color palette of more than 20 colors but it only seems to use the first 20 colors and then it repeats the first color in my palette for all series after 20.

What I would like to do is have the color cycle through All the colors from the beginning again.
Or even better I would like to have a palette of about 50 colors and cycle through these.

Is this possible?
Are there any events in the theme/color palette selection that I can hook into to select the color myself?

After a theme/palette has been set it seems like I can't even set the linePen color for each series I add manually. The LinePen seems to come from the theme or first color palette chosen.

Any help would be appreciated.

Kind Regards
Freddie

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Cycling colors with more than 20 series?

Post by Yeray » Mon Mar 22, 2010 3:50 pm

Hi Freddie,

The following code seems to work fine here. Could you please try if it works at your end?

Code: Select all

        Color[] CustomPalette;
        Steema.TeeChart.WPF.Styles.Bar bar1;

        private void InitializeChart()
        {
            bar1 = new Steema.TeeChart.WPF.Styles.Bar(tChart1.Chart);
            bar1.FillSampleValues(30);
            bar1.ColorEach = true;

            CustomPalette = new Color[5];
            Random rnd = new Random();
            for (int t = 0; t < CustomPalette.Length; ++t) CustomPalette[t] = Color.FromRgb(Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255)));

            Steema.TeeChart.WPF.Themes.ColorPalettes.ApplyPalette(tChart1.Chart, CustomPalette);            
        }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Freddie
Newbie
Newbie
Posts: 13
Joined: Thu Jun 25, 2009 12:00 am

Re: Cycling colors with more than 20 series?

Post by Freddie » Tue Mar 23, 2010 9:07 am

Hi Yeray,

That code works fine but I am not interested in coloring each point on the graph, only the whole line or series.

Have a look at this simple example.

Code: Select all

            Steema.TeeChart.WPF.Styles.Series line1 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
            line1.FillSampleValues(10);
            Steema.TeeChart.WPF.Styles.Series line2 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
            line2.FillSampleValues(10);
            Steema.TeeChart.WPF.Styles.Series line3 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
            line3.FillSampleValues(10);
            Steema.TeeChart.WPF.Styles.Series line4 = new Steema.TeeChart.WPF.Styles.Line(tChart1.Chart);
            line4.FillSampleValues(10);

            CustomPalette = new Color[2];
            CustomPalette[0] = Colors.Red;
            CustomPalette[1] = Colors.Blue;
Here I set a palette of 2 colors and then I add 4 series to the graph. In the example, the first two series are different colors from the palette but then the third and forth series repeat the first color in the palette. It does not recycle through the palette colors. So when I have a palette of 40 colors, it colors the first 40 series correctly but then repeats the first color for every series after 40. This is a problem when I don't know how many series are going to be added to the graph in advance - I simply want to reuse the colors I have when the palette is not big enough.


Do you know a neat way of reusing the palette so that it cycles through all the colors in the palette for each series added after the palette size?

Many Thanks
Freddie

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Cycling colors with more than 20 series?

Post by Yeray » Wed Mar 24, 2010 4:03 pm

Hi Freddie,

I could reproduce the problem so I've added it to the defect list to be fixed in further releases (TF02014749).
Note that, as a workaround, you could assign the appropriate color manually:

Code: Select all

for (int i = 0; i < tChart1.Series.Count; i++) tChart1[i].Color = CustomPalette[i % CustomPalette.Length];
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply