2017-02-15 2 views

답변

1

AxisLabels이를 달성하기 위해 어느 속성도 CustomAttributes있다.

그러나 CustomLabels이 작업을 멋지게 처리합니다.

Random rnd = new Random(0); 
List<Color> colors = new List<Color>() { Color.Red, Color.Firebrick, Color.Gold, 
    Color.DeepPink, Color.Azure, Color.IndianRed, Color.ForestGreen }; 

ChartArea ca = chart.ChartAreas[0]; 

Series s = chart.Series[0]; 

for (int i = 1; i < 7; i++) 
{ 
    s.Points.AddXY(i, i+ rnd.Next(20 - i)); 
} 

지금 CustomLabels을 추가

enter image description here

데이터를 설정 : 여기

SeriesDataPoint 대한 CustumLabel 추가하고 그것을 임의의 색상을 제공 한 예이다 :

foreach (var dp in s.Points) 
{ 
    CustomLabel cl = new CustomLabel(); 
    cl.FromPosition = dp.XValue; 
    cl.ToPosition = dp.XValue ; 
    cl.Text = dp.YValues[0]+ "$"; 
    cl.ForeColor = colors[rnd.Next(colors.Count)]; 

    ca.AxisX.CustomLabels.Add(cl); 
} 

ChartType Radar의 경우 이것은 다소 단순합니다. FromPositionToPosition을 얻는 대부분의 다른 유형은 다소 까다 롭습니다. 두 점 사이의 중심을 계산해야합니다.

+0

거룩한 암소! 이것은 훌륭했다. 고마워. – Kasra

+0

'MarkerBorderColor'에도'DataPoint' 색상을 사용할 수 있습니까? @TaW – Kasra

+0

물론입니다. 그래도 MarkerStyle을 설정했는지 확인하십시오 ..! -'dp.MarkerBorderColor = cl.ForeColor; dp.MarkerColor = Color.MediumAquamarine; dp.MarkerStyle = MarkerStyle.Diamond; dp.MarkerSize = 10;'- [예제] (http://imgur.com/a/TTrcl) – TaW

관련 문제