I have a bar chart which shows different categories on the Y axis.
I can change the color of all of them on the axis at the same time by using:
chart.ChartAreas["MyChart"].AxisY.LabelStyle.ForeColor = "Red";
However it doesn't allow me to set the color for each of them.
Any help will be much appreciated.
Set up X-axis and Y-axis labels using set_xlabel and set_ylabel method for creating ax using add_subplot(). To set the color for X-axis and Y-axis, we can use the set_color() method (Set both the edgecolor and the facecolor). To set the ticks color, use tick_params method for axes.
Just click to select the axis you will change all labels' font color and size in the chart, and then type a font size into the Font Size box, click the Font color button and specify a font color from the drop down list in the Font group on the Home tab.
On a chart, select the individual data marker that you want to change. On the Format tab, in the Shape Styles group, click Shape Fill. Do one of the following: To use a different fill color, under Theme Colors or Standard Colors, click the color that you want to use.
You can try adding custom labels to the chart, and that will allow you to modify each one individually.
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);
}
Ok The only solution I have found is to create a custom label and set the color that way:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With