2013-04-02 238 views
0

我想下面的代碼創建條形圖,其中條必須由用戶名進行分組,但不知何故讓問題標籤重複如下圖所示,的MSChart:標籤在條形圖中的X軸重複

enter image description here

我的數據表是一樣的東西,

Question="Gravimetry" 
Project-test1=0 
Project-test2=1 

Question="Sub-Surface" 
Project-test1=0 
Project-test2=2 

Question="VSP" 
Project-test1=2 
Project-test2=3 
..... 

C#是,

  Series Series = new Series("Series1"); 
      Chart4.Series.Add("Series1"); 
      Chart4.Series.Add("Series2"); 

      Chart4.ChartAreas.Add("ChartArea1"); 

      // Set series chart type 
      Chart4.Series["Series1"].ChartType = SeriesChartType.Bar; 
      Chart4.Series["Series2"].ChartType = SeriesChartType.Bar; 


      // Set series point width 
      Chart4.Series["Series1"]["PointWidth"] = "0.6"; 
      Chart4.Series["Series2"]["PointWidth"] = "0.6"; 

      // Show data points labels 
      Chart4.Series["Series1"].IsValueShownAsLabel = true; 
      Chart4.Series["Series2"].IsValueShownAsLabel = true; 

      // Set data points label style 
      Chart4.Series["Series1"]["BarLabelStyle"] = "Center"; 
      Chart4.Series["Series2"]["BarLabelStyle"] = "Center"; 

      // Draw as 3D Cylinder 
      Chart4.Series["Series1"]["DrawingStyle"] = "Cylinder"; 
      Chart4.Series["Series2"]["DrawingStyle"] = "Cylinder"; 

      Chart4.DataSource = dt.DefaultView; 

      Chart4.ChartAreas["ChartArea1"].AxisX.Interval = 1; 

      Chart4.Series["Series1"].XValueMember = "Question"; 

      //Chart4.Series["Series1"].YValuesPerPoint = 2; 

      Chart4.Series["Series1"].YValueMembers = "Project-test1"; 
      Chart4.Series["Series2"].YValueMembers = "Project-test2"; 

      Chart4.DataBind(); 

任何幫助將不勝感激!

回答

0

看看Chart.DataBindTable method;它似乎綁定到表並按列提供分組。例如:

Chart4.DataBindTable(dt, "Question"); 

應該爲表中的每個附加列創建一個系列,按問題列進行分組。

如果您需要更多定製,還有Chart.DataBindCrossTable method,它允許您指定哪些列用於創建系列值。