2012-03-28 5 views
4

여러 시리즈가있는 차트가 있습니다. foreach Series를 자동으로 다른 색상으로 설정하려면 ChartColorPalette를 사용하고 있습니다.ChartColorPalette를 사용할 때 런타임 중에 Series.Color를 읽으려면 어떻게해야합니까?

그 순간, 시리즈를 만들 때 Color를 읽고 dropDownList.listItem에 같은 backgroundColor를 지정하려고합니다. 그러나 안타깝게도 바로 그 순간에 Color는 아직 설정되지 않았습니다.

나중에 ASP.NET의 Rendering-Event에서 Series가 ChartColorPalette에서 색상 정의를 가져 오지 않을 수 있습니까?

내가 뭘 잘못하고 있니?

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 + ";"); 
} 
+0

그것은 당신의 코드에서 newSeries하지 Newseries을해야하지? – Quantbuff

+0

예. 나는 그것을 고쳤다. – Zahnfee

답변

17

Dundas 사이트 (MS 원본 차트 원본 코드)에서 수동으로 팔레트를 적용 할 수 있습니다.

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

나는 당신이 팔레트를 적용하고 드롭 다운을 채울 밖으로 색상을받은 후 그들을 통해 먼저 다음 루프에서 시리즈를 모두 추가해야합니다 생각합니다.

Dundas - How to retrieve colors from the chart color palette

+0

고마워요! 그게 바로 제가 찾고있는 것입니다 =) – Zahnfee

+0

저에게 생명을 구해주었습니다! 감사! – hansioux

0

왜 ChartColor Pallette를 직접 사용하지 않으시겠습니까?

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

이것으로'ChartColorPalette' 열거 형에 대한 값을 얻을 수 있습니다. 색상과 관련이 없습니다. – V4Vendetta

+0

Yap, 각 색상 중 하나가 아니라 팔레트의 이름 만 가져옵니다. 그것이 가능할 지 확신 할 수 없습니다. 그러나 그것이 깨끗한 해결책이 아닐지라도. – Zahnfee

관련 문제