2011-07-27 9 views
2

winfowアプリケーションでは、2つのチャート領域を持つmsチャートがあります。 最初のグラフ領域には4つのシリーズ(積み重ね、棒)が含まれています特定のデータポイントのMicrosoft Chart Control X Axisラベルの書式設定

特定のポイントではX軸のラベルの色を変更する必要がありますが、VS 2010では色のみ変更できます。

これを行う方法はありますか?このリンクで

答えて

2

:あなたは軸のラベルを変更するLabelStyleクラスの使用を見つけるでしょうhttp://msdn.microsoft.com/en-us/library/dd456628.aspx

。ラベルの色を変更するには、LabelStyle.ForeColorプロパティを使用します。

+0

私はそれを見ましたが、スタイルは軸全体に適用されます。私はすべてのポイントではなく、シリーズのいくつかのポイントのためだけに赤でx軸のラベルを入れてください – Webmixer

+0

誰も助けることができますか?この質問にはまだ答えがありません。 – Webmixer

1

私はこれがOPのためには遅すぎると知っていますが、これを行う方法を探している他の人にとっては有用かもしれません。

カスタムラベルでは色を設定できますが、カスタムラベルを1つ追加するとすべての標準ラベルが消えてしまうため、軸全体のカスタムラベルを作成してから、異なっていたい。

このコードは、すべてのX値に対してラベルが必要であることを前提としています。多数のX値がある場合は、コードを調整する必要があります。

double offset = 0.5;//Choose an offset that is 1/2 of the range between x values 
for (int i = 0; i < chart1.Series[0].Points.Count; i++) 
{ 
    var customLabel = new CustomLabel(); 
    //NOTE: the custom label will appear at the mid-point between the FromPosition and the ToPosition 
    customLabel.FromPosition = chart1.Series[0].Points[i].XValue - offset; //set beginning position (uses axis values) 
    customLabel.ToPosition = chart1.Series[0].Points[i].XValue + offset; //set ending position (uses axis values) 
    customLabel.Text = chart1.Series[0].Points[i].XValue.ToString(); //set the text to display, you may want to format this value 
    if (i == 3) 
    { 
    customLabel.ForeColor = Color.Green;//only change the 3rd label to be green, the rest will default to black 
    } 
    chart1.ChartAreas[0].AxisX.CustomLabels.Add(customLabel); 
}