C#图表旋转标签

C#图表旋转标签,c#,charts,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 }); mySeri

我有一个简单的图表,我希望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);
输出为:


我正在使用System.Web.UI.DataVisualization.charting中的制图工具。

文档中说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

以下是我通常如何旋转X轴标签

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


上面要查看的关键属性/行是“LabelAutoFitStyle”。

我需要这些行来让它工作:

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

我知道这个问题已经老生常谈了。我只想说Series.LabelAngle控制系列的“标签,而不是轴”。如果添加这两条线,标签将显示在柱的上方,并旋转45度:

mySeries.IsValueShownAsLabel = true;
mySeries.SmartLabelStyle.Enabled = false;

所以你必须像Maciej Rogoziński所说的那样设置AxisX的LabelAngle。

Axis.IsLabelAutoFit默认值为true,因此必须将其设置为false才能应用LabelStyle.Angle。

哇,没有阅读45度的要求,但它可能会帮助某些人……我最近试图用area的对象旋转标签,那是行不通的。添加图表对象使其像一个符咒一样工作。