2017-02-26 32 views
-2

我想改變一些AxisLabelsin一些系列爲我的圖表的MSChart:我怎樣才能改變一些AxisLabels

  DataTable dt = new DataTable(); 
      SqlCommand s = new SqlCommand("ReportMonthly", SCon); 
      s.CommandType = CommandType.StoredProcedure; 
      s.Parameters.AddWithValue("@Y", Y); 
      SCon.Open(); 
      SqlDataReader dr = s.ExecuteReader(); 
      dt.Load(dr);    
      chtWRMonthly.DataSource = dt; 
      chtWRMonthly.Series["Sold"].XValueMember = "x";    
      chtWRMonthly.Series["sRemaining"].XValueMember = "x";    
      chtWRMonthly.Series["Bought"].XValueMember = "x";    
      chtWRMonthly.Series["bRemaining"].XValueMember = "x"; 

      chtWRMonthly.Series["Sold"].YValueMembers = "sTAccount"; 
      chtWRMonthly.Series["sRemaining"].YValueMembers = "sRemaining"; 
      chtWRMonthly.Series["Bought"].YValueMembers = "bTAccount"; 
      chtWRMonthly.Series["bRemaining"].YValueMembers = "bRemaining"; 
      SCon.Close(); 

      //انتصاب نام ماه ها 
      foreach (Series SR in chtWRMonthly.Series) 
      { 
       foreach (DataPoint DP in SR.Points) 
       { 
        switch (DP.AxisLabel) 
        { 
         case "1": 
          DP.AxisLabel = "x1"; 
          break; 
         case "2": 
          DP.AxisLabel = "x2"; 
          break; 
         case "3": 
          DP.AxisLabel = "x3"; 
          break; 
         case "4": 
          DP.AxisLabel = "x4"; 
          break; 
        }       
       } 
      } 

我試圖通過一個開關來改變他們,但什麼都沒有發生。

+0

你可以在這裏添加你的代碼給初學者嗎? –

回答

2

您的DataPoints沒有真實AxisLabels。他們顯示的字符串是從DataPoint.XValues自動創建的。

所以你的開關永遠不會打。

通過

switch (DP.XValue + "") 

更換

switch (DP.AxisLabel) 

,它會工作。

請注意,我已經轉換了doubleXValuestring以配合您的switch代碼。如果將switch選項更改爲numbers,則可以直接使用它。

後您已設置AxisLabels你可以把它們用於測試,但直到然後..

見各種圖表標籤here for a good overview