5
我有一个条形图,显示Y轴上的不同类别。质谱图:如何更改条形图轴上每个标签的颜色?
我可以通过改变在同一时间轴个个颜色:
chart.ChartAreas["MyChart"].AxisY.LabelStyle.ForeColor = "Red";
然而,它没有让我设置颜色为他们每个人。
任何帮助将不胜感激。
我有一个条形图,显示Y轴上的不同类别。质谱图:如何更改条形图轴上每个标签的颜色?
我可以通过改变在同一时间轴个个颜色:
chart.ChartAreas["MyChart"].AxisY.LabelStyle.ForeColor = "Red";
然而,它没有让我设置颜色为他们每个人。
任何帮助将不胜感激。
好,我已经找到了唯一的解决方案是创建一个自定义标签,并设置颜色的方法:
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);
您可以尝试向图表添加自定义标签,并允许您分别修改每个标签。
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);
}