我有一个条形图,在Y轴上显示不同的类别。
我可以使用以下方法同时更改轴上所有这些颜色:
chart.ChartAreas["MyChart"].AxisY.LabelStyle.ForeColor = "Red";
然而,它不允许我为每一个设置颜色。
非常感谢任何帮助。
答案 0 :(得分: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);
}
答案 1 :(得分:2)
确定我找到的唯一解决方案是创建自定义标签并设置颜色:
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);