Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read the Series.Color during runtime when using a ChartColorPalette?

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 + ";");
}
like image 329
np00 Avatar asked Mar 28 '12 13:03

np00


1 Answers

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.

like image 101
Justin Wignall Avatar answered Nov 09 '22 09:11

Justin Wignall