簡體   English   中英

MS Chart:如何更改條形圖軸上每個標簽的顏色?

[英]MS Chart: How can you change the color of each label on the Axis of a Bar Chart?

我有一個條形圖,顯示Y軸上的不同類別。

我可以通過使用以下方法同時更改軸上所有這些顏色:

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

但是它不允許我為每個設置顏色。

任何幫助都感激不盡。

您可以嘗試向圖表添加自定義標簽,這樣您就可以單獨修改每個標簽。

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);
}

確定我找到的唯一解決方案是創建自定義標簽並設置顏色:

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM