添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
温柔的上铺  ·  中国公路学报·  2 月前    · 
眼睛小的香瓜  ·  Convert reference Python·  5 月前    · 
欢乐的黄豆  ·  PDFsharp & MigraDoc ...·  7 月前    · 
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
                I was trying to rotate the labels with area's object lately, that was not working. Appending chart object makes it work like a charm.
– Zeeshan Ajmal
                Dec 3, 2015 at 13:57
 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.