2014-03-12 57 views
0

如何設置使用radChart因爲我收到IndexOutOfRange例外,我沒有什麼behaind這個原因,X軸標籤設置radChart值的Y軸標籤。如何使用列表<string>

public void setchart() 
{ 
    radChart.Clear(); 
    radChart.BringToFront(); 
    radChart.ChartTitle.TextBlock.Text = "Total Number Of Units Per Rack"; 
    this.Controls.Add(radChart); 
    radChart.Dock =DockStyle.Fill; 
    radChart.PlotArea.Appearance.Dimensions.Height = 500; 
    radChart.PlotArea.XAxis.AxisLabel.Visible = true; 
    radChart.PlotArea.XAxis.AxisLabel.TextBlock.Text = "UnitProcessDetailType"; 
    radChart.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red; 
    radChart.PlotArea.XAxis.Appearance.Width = 1; 
    radChart.PlotArea.XAxis.Appearance.Color = System.Drawing.Color.Red; 
    radChart.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 45; 

    radChart.PlotArea.YAxis.AxisLabel.Visible = true; 
    radChart.PlotArea.YAxis.AxisLabel.TextBlock.Text = "Number Of Units"; 
    radChart.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Color = System.Drawing.Color.Red; 
    radChart.PlotArea.YAxis.Appearance.Width = 1; 
    radChart.PlotArea.YAxis.Appearance.Color = System.Drawing.Color.Red; 
    radChart.Chart.Skin = "Sunset"; 

    Telerik.Charting.ChartSeries chartSeries = new Telerik.Charting.ChartSeries(); 
    chartSeries.Name = "Number Of Units Per Type"; 
    chartSeries.Type = Telerik.Charting.ChartSeriesType.Bar; 
    chartSeries.Appearance.BarWidthPercent = 70; 
    radChart.PlotArea.XAxis.AutoScale = false; 

    ReportGrid.Controls.Add(radChart); 

    List<string> xaxisLabel = new List<string>(); 
    List<string> yaxislabel = new List<string>(); 

    if (masterTab1.HeaderGrid.CurrentRow.Cells[0].Value.ToString() == "Sales Quotes by Quote Status") 
    { 
     DataTable table = new DataTable(); 

     table = Adapter.SalesQuotesbyQuoteStatus(GroupList.SelectedText.ToString(), TimePeriodList.SelectedText.ToString()); 

     int number = table.Rows.Count; 
      int column = table.Columns.Count; 
      radChart.PlotArea.XAxis.AddRange(1, number, 1); 
      radChart.PlotArea.YAxis.AddRange(1 , 1 , 1); 
     foreach (DataRow dr in table.Rows) 
     { 
      xaxisLabel.Add(dr["X_Axis"].ToString()); 
      yaxislabel.Add(dr["Y_Axis"].ToString()); 
     } 

     for (int i = 0; i < table.Rows.Count; i++) 
     { 
      chartSeries.AddItem(Convert.ToDouble(yaxislabel[i]), xaxisLabel[i]); 
     } 

     for (int xaxis = 0; xaxis < xaxisLabel.Count; xaxis++) 
     { 
       radChart.PlotArea.XAxis[xaxis].TextBlock.Text = xaxisLabel[xaxis]; 
     } 

     for (int yaxis = 0; yaxis < yaxislabel.Count; yaxis++) 
     { 
      radChart.PlotArea.YAxis[yaxis].TextBlock.Text = yaxislabel[yaxis]; 
     } 

      radChart.Series.Add(chartSeries); 

     } 



    } 

列表中也含有因爲我已經檢查一遍值又一遍,現在我不知道什麼是真正的問題?

回答

0

我不知道確切的問題,但該錯誤IndexOutOfRangeException可能是這樣的,如下所示背後的原因,

例如: 在主,我們使用長度100的新的數組這意味着數組是對大小爲100的整數的對象數據的引用。可以通過數組下標訪問數組元素,與陣列[0],陣列[1],通過陣列[99]。

提示:您可以訪問的頂部索引等於總長度減1。如果你過去99訪問一個索引,你會得到一個IndexOutOfRangeException。

相關問題