C#图表旋转标签
我有一个简单的图表,我希望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;