How can I read Series.Color at runtime when using ChartColorPalette?

I have a chart with several rows. I use ChartColorPalette to set a different color for the Foreach series automatically.

The moment I create my series, I want to read Color to give dropDownList.listItem the same backgroundColor. But, unfortunately, at this point the Color is not yet set.

Is it possible that the Series will derive its color definition from the ChartColorPalette later in the ASP.NET Rendering-Event?

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 + ";"); } 
+4
source share
2 answers

From the Dundas website (the source for MS graphic programming code), you can force it to apply the palette manually.

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

I would think that you would need to add all the series in the first place, and then scroll through them after applying the palette and get the colors to populate the drop-down list.

Dundas - How to get colors from the chart color palette

+17
source

Why don't you just use ChartColor Pallette directly?

 foreach(string colorName in Enum.GetNames(typeof(ChartColorPallette)) { } 
0
source

Source: https://habr.com/ru/post/1403911/


All Articles