5

I have a chart with multiple Series. I am using the ChartColorPalette to set foreach Series automatically a different color.

In that moment, when I am creating my Series, I want to read the Color to give a dropDownList.listItem the same backgroundColor. But unfortunately, in that very moment, the Color is still not set.

Is it possible that the Series are getting their color-definition out of the ChartColorPalette later in the Rendering-Event of ASP.NET?

Or what am I doing wrong?

Chart newChart = new Chart();
newChart.Palette = ChartColorPalette.Bright;

Series newSeries;

foreach (....)
{
   newSeries = new Series();
   newChart.Series.Add(newSeries);

   // no color found :(
   string colorName = newSeries.Color.Name

   // same here
   string colorName = newChart.Series[identifier].Color.Name;

   myDropDownList.Items.FindByValue(identifier).Attributes.Add("style", "background: " + colorName + ";");
}
np00
  • 218
  • 2
  • 6

2 Answers2

19

From the Dundas site (original source of MS charting code and no longer available online as of Aug 2018) you can force it to apply the palette manually.

newChart.ApplyPaletteColors();
Color thisColor = newChart.Series[identifier].Color;

I would think you will need to add all of the series in first and then loop through them after applying the palette and getting the colours out to populate the drop down.

Justin Wignall
  • 3,490
  • 20
  • 23
-1

Why dont you just use ChartColor Pallette directly ?

foreach(string colorName in Enum.GetNames(typeof(ChartColorPallette))
{
}
Quantbuff
  • 827
  • 7
  • 9
  • By this you get values for `ChartColorPalette` enums, nothing to do with the colors – V4Vendetta Mar 29 '12 at 06:54
  • Yap, I do only get the name of the Palettes and not the one of each color. I'm not sure whether that is even possible. But even if, I think it would not be a clean solution. – np00 Mar 29 '12 at 11:35