将数据点动态添加到图表时出现问题。没有显示任何值

发布于 2024-11-04 08:23:01 字数 1597 浏览 9 评论 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。我有什么明显遗漏的东西吗?

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" 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>

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃气十足 2024-11-11 08:23:06

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

        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 asis 的值......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文