我有一个条形图,显示了不同类别在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);