0

我正在尝试学习 asp.net 中的图表控件,但我遇到了一些问题。

我要做的就是制作一个简单的柱形图。每列都应该有一个名称。我想在代码隐藏中操作数据库中的数据,并在图表中添加一列,该列上有一个名称。

我正在查看的示例将它们添加到 .ascx 文件中。在代码隐藏中做同样的事情应该是直截了当的,但不知何故它不起作用。我正在查看的示例是这样的:

<asp:Chart ID="chtNBAChampionships" runat="server">
<Series>
    <asp:Series Name="Championships" YValueType="Int32" Palette="Berry"     ChartType="Column"
        ChartArea="MainChartArea" IsValueShownAsLabel="true">
        <Points>                
            <asp:DataPoint AxisLabel="Celtics" YValues="0" />
            <asp:DataPoint AxisLabel="Lakers" YValues=" />
            <asp:DataPoint AxisLabel="Bulls" YValues="6" />
            <asp:DataPoint AxisLabel="Spurs" YValues="4" />
            <asp:DataPoint AxisLabel="76ers" YValues="3" />
            <asp:DataPoint AxisLabel="Pistons" YValues="3" />
            <asp:DataPoint AxisLabel="Warriors" YValues="3" />
            <asp:DataPoint AxisLabel="Mara" YValues="4" />
            <asp:DataPoint AxisLabel="Saza" YValues="9" />
            <asp:DataPoint AxisLabel="Buha" YValues="6" />
        </Points>
    </asp:Series>
</Series>
<ChartAreas>
    <asp:ChartArea Name="MainChartArea">
    </asp:ChartArea>
</ChartAreas>

我尝试在代码隐藏中添加一个数据点,如下所示:

    DataPoint dp = new DataPoint();
    dp.AxisLabel = "Test";
    dp.YValues = new double[18];

    this.chtNBAChampionships.Series["Championship"].Points.Add(dp);

但这只会在图表中给我一个 0。我有什么明显的遗漏吗?

4

1 回答 1

0

这是我正在使用的代码片段:

        dp = new DataPoint(i++, value);
        dp.AxisLabel = axisName;
        dp.ToolTip = axisName;
        dp.SetValueY(value);
        dp.IsValueShownAsLabel = true;
        s1.Points.Add(dp);
        dp.XValue = s1.Points.Count;

其中 s1 是 Series 对象。也许您也需要指定 X 轴的值...

于 2011-04-30T01:05:42.457 回答