Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# chart rotate labels

Tags:

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:

img

I'm using the charting stuff from System.Web.UI.DataVisualization.Charting.

like image 801
Xodarap Avatar asked May 18 '11 16:05

Xodarap


1 Answers

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 
like image 144
Maciej Rogoziński Avatar answered Sep 17 '22 19:09

Maciej Rogoziński