Page 1 of 1
Cycling colors with more than 20 series?
Posted: Fri Mar 19, 2010 5:39 pm
by 15653576
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
Re: Cycling colors with more than 20 series?
Posted: Mon Mar 22, 2010 3:50 pm
by yeray
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);
}
Re: Cycling colors with more than 20 series?
Posted: Tue Mar 23, 2010 9:07 am
by 15653576
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
Re: Cycling colors with more than 20 series?
Posted: Wed Mar 24, 2010 4:03 pm
by yeray
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];