帮助ASP.NET C#图表控件

时间:2011-06-20 10:40:24

标签: c# asp.net charts

我有以下数据集:

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

更新

我的.aspx文件中有以下内容

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

1 个答案:

答案 0 :(得分: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>