C#图表旋转标签

Xod*_*rap 21 c# charts

我有一个简单的图表,我希望x轴上的标签旋转45度.我究竟做错了什么?

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);
Run Code Online (Sandbox Code Playgroud)

输出是:

IMG

我正在使用System.Web.UI.DataVisualization.Charting中的图表.

Mac*_*ski 29

文档说Series.LabelAngle设置数据点标签角度,(我认为)是图表列上方的标签.

要设置轴标签的角度,请尝试以下方法:

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
Run Code Online (Sandbox Code Playgroud)


Zac*_*ary 18

以下是我通常旋转X轴标签的方法.

 ChartArea area = new ChartArea();
 area.AxisX.IsLabelAutoFit = true;
 area.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep30;
 area.AxisX.LabelStyle.Enabled = true;
Run Code Online (Sandbox Code Playgroud)

结果

在此输入图像描述

上面看的关键属性/行是"LabelAutoFitStyle".