C# chart rotate labels

The documentation says that Series.LabelAngle sets data point label angle, which (I think) is a label above the chart's column.

To set an angle of axis labels try this one:

var c = Chart1;
c.ChartAreas.Add(new ChartArea());
c.Width = 200;
c.Height = 200;
Series mySeries = new Series();
mySeries.Points.DataBindXY(new string[] { "one", "two", "three" }, new int[] { 1, 2, 3 });
//mySeries.LabelAngle = -45; // why doesn't this work?
c.Series.Add(mySeries);
c.ChartAreas[0].AxisX.LabelStyle.Angle = 45; // this works

Here is how I usually rotate my X Axis labels.

 ChartArea area = new ChartArea();
 area.AxisX.IsLabelAutoFit = true;
 area.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30;
 area.AxisX.LabelStyle.Enabled = true;

Results

enter image description here

The key property/line to look at above is the "LabelAutoFitStyle".


I needed these lines to get it to work:

chartarea.AxisX.LabelStyle.Angle = -90;
chartarea.AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
chartarea.AxisX.IsLabelAutoFit = false;

Tags:

C#

Charts