2011-06-20 68 views
1

我有以下數據集:幫助ASP.NET C#圖表控件

NAME | GP | ORD_GP | EXP | TOTAL GP | TARGET 
a  206  48  -239  15   1600 
b  0  27  0  27  1520 

我嘗試使用下面的代碼在圖表中顯示,這一切我想要顯示的是NAME TOTAL_GPTARGET

Chart1.Width=600; 
    Chart1.BackColor = Color.Gray; 
    Chart1.BackSecondaryColor = Color.WhiteSmoke; 
    Chart1.BackGradientStyle = GradientStyle.DiagonalRight; 
    Chart1.BorderlineDashStyle = ChartDashStyle.Solid; 
    Chart1.BorderlineColor = Color.Gray; 
    Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss; 

    // format the chart area 
    Chart1.ChartAreas[0].BackColor = Color.Wheat; 
    // add and format the title 
    Chart1.Titles.Add("ASP.NET Chart"); 
    Chart1.Titles[0].Font = new Font("Utopia", 16); 

    // clear the chart series and bind to the table 
    Chart1.DataSource = ds.Tables[0]; 
    Chart1.Series[0].XValueMember = "NAME"; 
    Chart1.Series[0].YValueMembers = "TOTAL_GP"; 

    Chart1.Series[0].ChartType = SeriesChartType.StackedBar; 

但是我不斷收到錯誤。請你能告訴我可能做錯了什麼。該錯誤是如下

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. 
Must be non-negative and less than the size of the collection. 
parameter name: index 

UPDATE

我在.aspx文件下面

<asp:Chart ID="Chart1" runat="server"> 
     <ChartAreas> 
      <asp:ChartArea Name="ChartArea1" /> 
     </ChartAreas> 
    </asp:Chart> 
+0

你在哪一行得到錯誤? – CResults

+0

Chart1.Series [0] .XValueMember =「NAME」; – c11ada

回答

0

解決了這個問題,不得不.aspx文件更改爲

<asp:Chart ID="Chart1" runat="server"> 
    <Series> 
     <asp:Series Name="Series1"> 
     </asp:Series> 
    </Series> 
    <ChartAreas> 
     <asp:ChartArea Name="ChartArea1"> 
     </asp:ChartArea> 
    </ChartAreas> 
</asp:Chart>