2011-05-18 92 views
17

我有一個簡單的圖表,我希望X軸上的標籤旋轉45度。我究竟做錯了什麼?C#圖表旋轉標籤

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); 

輸出是:

img

我使用的是從System.Web.UI.DataVisualization.Charting製圖的東西。

回答

25

該文檔說,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 
+0

我想最近旋轉與區域的對象的標籤,這是行不通的。追加圖表對象使其像魅力一樣工作。 – 2015-12-03 13:57:01

16

下面是我通常我的旋轉X軸標籤。

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

結果

enter image description here

的關鍵性質/線在高於看是 「LabelAutoFitStyle」。

0

我需要這些行得到它的工作:

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

哎呀,沒有讀過45度的要求,但它可能會幫助別人...... – Sean 2015-04-09 21:20:21