2014-10-02 47 views
0

我有圖表與列類型(2系列):
- 一個系列爲男性。
- 一個女系列。
一切都很好,但我想設置X1,在底部X2標籤(X軸):更改X軸標籤的位置與2系列

enter image description here

我想把[單位#3333和單位#0099]在底部,[單元#1111和單元#555]

可能嗎?

下面的代碼(CS文件):

using System; 
using System.Collections.Generic; 
using System.Data.SqlClient; 
using System.Drawing; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.DataVisualization.Charting; 

namespace PCMD.AssignTransferSystem.web.Managers 
{ 
    public partial class ColumnChart : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true; 
      Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = true; 
      Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false; 
      Chart1.ChartAreas["ChartArea1"].Area3DStyle.PointDepth = 20; 
      Chart1.ChartAreas["ChartArea1"].Area3DStyle.Perspective = 0; 
      SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=AssignTransferDB;Integrated Security=True"); 
      conn.Open(); 
      SqlCommand cmd = new SqlCommand(); 
      cmd.Connection = conn; 


     string cmdstr = "select * from ReqUnitsByGender"; // View in DB 
     cmd.CommandText = cmdstr; 
     SqlDataReader Dr = cmd.ExecuteReader(); 

     Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; 
     Chart1.ChartAreas["ChartArea1"].AxisX2.Interval = 1; 
     //Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("Arial", 16); 
     //Chart1.ChartAreas["ChartArea1"].AxisX2.LabelStyle.Font = new Font("Arial", 16); 
     //Chart1.Series["male"].IsValueShownAsLabel = true; 
     //Chart1.Series["female"].IsValueShownAsLabel = true; 
     //Chart1.Series["male"]["LabelStyle"] = "Bottom"; 
     //Chart1.Series["female"]["LabelStyle"] = "Bottom"; 
     //Chart1.Series["male"]["BarLabelStyle"] = "Bottom"; 
     //Chart1.Series["female"]["BarLabelStyle"] = "Bottom"; 
     while (Dr.Read()) 
     { 
      if (Dr["Gender"].ToString()=="True") 
      { 
       Chart1.Series["male"].Points.AddXY(Dr["UnitName"].ToString(), Dr["CountRequest"].ToString()); 
       Chart1.Series["male"].XAxisType = AxisType.Primary; 
      } 
      if (Dr["Gender"].ToString() == "False") 
      { 
       Chart1.Series["female"].Points.AddXY(Dr["UnitName"].ToString(), Dr["CountRequest"].ToString()); 
       Chart1.Series["female"].XAxisType = AxisType.Secondary;    
      } 
     } 
     conn.Close(); 
    } 
} 
} 
+1

發佈您的代碼,瞭解如何設置圖表。 – mmathis 2014-10-02 13:58:59

+0

你可以在答案部分看到我的代碼bro @mmathis – 2014-10-02 19:51:58

+0

謝謝。但是,您的代碼不是答案,因此請編輯您的問題並在其中發佈代碼,然後使用您的代碼刪除答案。 – mmathis 2014-10-02 20:17:02

回答

0

您使用的是二次X軸爲你的 「女性」 系列。將其更改爲

Chart1.Series["female"].XAxisType = AxisType.Primary; 

並且您應該全部設置。但是,如果這兩個系列不具有相同的x值,那麼這些條可能會在它們之間留有空間。

+0

我把一個系列[]小學另一個是中學<放每個系列顯示甚至是系列有一個值> 例如(如果我把兩個系列小學): 系列[「女性」]覆蓋第一個標籤 – 2014-10-02 21:25:18

+0

我不太清楚你所描述的是什麼......你可以發佈你想要的情節模型嗎?你可以嘗試使用輔助x軸的'AxisCrossing'屬性,但是你可能會得到重疊的標籤。一般來說,主x軸位於圖的底部,次位於頂部 - 這些也是相關標籤的位置。如果你想在底部標籤,你應該使用主軸。 – mmathis 2014-10-02 22:30:52