Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a simple chart, and I'd like the labels on the x-axis to be rotated 45 degrees. What am I doing wrong?
Chart c = new Chart();
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);
The output is:
I'm using the charting stuff from System.Web.UI.DataVisualization.Charting.
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
–
ChartArea area = new ChartArea();
area.AxisX.IsLabelAutoFit = true;
area.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30;
area.AxisX.LabelStyle.Enabled = true;
Results
The key property/line to look at above is the "LabelAutoFitStyle".
chartarea.AxisX.LabelStyle.Angle = -90;
chartarea.AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
chartarea.AxisX.IsLabelAutoFit = false;
I know this question is old and answered. I just want to say that Series.LabelAngle controls series' label, not Axis'. If you add these two lines, the label would be shown above the column and is rotated 45 degrees:
mySeries.IsValueShownAsLabel = true;
mySeries.SmartLabelStyle.Enabled = false;
So you have to set AxisX's LabelAngle as Maciej Rogoziński said.