ASP.NET C#图表控件的帮助
本文关键字:控件 帮助 NET ASP | 更新日期: 2023-09-27 17:59:30
我有以下数据集:
NAME | GP | ORD_GP | EXP | TOTAL GP | TARGET
a 206 48 -239 15 1600
b 0 27 0 27 1520
我正试图使用以下代码在图表中显示这一点,我只想显示NAME TOTAL_GP
和TARGET
:
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>
解决了这个问题,不得不将.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>