2012-03-09 2 views
5

私はY軸に異なるカテゴリを示す棒グラフを持っています。MSチャート:棒グラフの軸上の各ラベルの色を変更するにはどうすればよいですか?

私が使用して同時に軸上でそれらのすべての色を変更することができます。

chart.ChartAreas["MyChart"].AxisY.LabelStyle.ForeColor = "Red"; 

をそれは私がそれらのそれぞれの色を設定することはできませんが。

ご協力いただければ幸いです。

答えて

2

[OK]を私が見つけた唯一の解決策は、カスタムラベルを作成し、その方法は、色を設定することです:

this._chart.ChartAreas[0].AxisX.CustomLabels.Add(new CustomLabel(position - 1, position + 1, point.AxisLabel, 0, LabelMarkStyle.None)); 

this._chart.ChartAreas[0].AxisX.CustomLabels[position - 1].ForeColor = GetColor(point.AxisLabel); 
4

グラフにカスタムラベルを追加すると、個々のラベルを個別に変更できるようになります。

private void AddCustomLabelAtYValue(double YValue, string Text, Color ForeColor) 
{ 
    double scale = chart.ChartAreas["MyChart"].AxisY.Maximum - 
     chart.ChartAreas["MyChart"].AxisY.Minimum; 
    double offset = scale * 0.5; 
    CustomLabel customLabel = new CustomLabel(YValue - offset, 
     YValue + offset, Text, 0, LabelMarkStyle.None); 
    customLabel.ForeColor = ForeColor; 
    chart.ChartAreas["MyChart"].AxisY.CustomLabels.Add(customLabel); 
} 
関連する問題