开发者

Problem adding datapoint dynamically to chart. No value shows up

I'm trying to learn the charting control in asp.net, but I am having some problems.

All I want to do is make a simple column chart. Every column should have a name. I want to manipulate data from a database in codebehind and add a column to the chart, with a name on that column.

The examples I'm reviewing adds them in .ascx file. Doing the same thing in codebehind should be straight forward, but somehow it does not work. The example I'm looking at is this:

<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" YValu开发者_开发技巧es="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>

I try to add a datapoint in codebehind like this:

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

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

But that only gives me a 0 in the graph. Is there something obvious I'm missing?


This is a code snippet I am using:

        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;

where s1 is the Series object. Maybe you need to specify the value for the X asis, too...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜