我需要帮助来绑定Asp.Net数据图表 [英] I need help to bind Asp.Net Data Chart

查看:68
本文介绍了我需要帮助来绑定Asp.Net数据图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想从SQL数据表中绑定数据图表。下面是我正在使用的代码。

Hello,
I want to bind data chart from the SQL Data table. Below is the code that I am using.

private string QueryString = "SELECT [Qty], [Hour], [ObjectifTotal] FROM [TRGCharts]";
  SqlConnection conn = new SqlConnection(ConnectionString);
           SqlCommand cmd = new SqlCommand(QueryString, conn);

           SqlDataAdapter da = new SqlDataAdapter();
           da.SelectCommand = cmd;
           DataTable dt = new DataTable();
           da.Fill(dt);
           Chart1.DataSource = dt;
           Chart1.Series["Series1"].XValueMember = dt.Columns["Hour"].ToString();
           Chart1.Series["Series1"].YValueMembers = dt.Columns["Qty"].ToString();
           Chart1.Series["Series2"].XValueMember = dt.Columns["Hour"].ToString();
           Chart1.Series["Series2"].YValueMembers = dt.Columns["ObjectifTotal"].ToString();
           Chart1.DataSource = dt;
           this.Chart1.Series["Series1"].Points.AddXY(dt.Columns["Hour"].ToString(), dt.Columns["Qty"].ToString());
           this.Chart1.DataBind();
           this.Chart1.Series["Series2"].Points.AddXY(dt.Columns["Hour"].ToString(), dt.Columns["ObjectifTotal"].ToString());
           this.Chart1.DataBind();



我的问题是它总是绑定Series1.....如果我做错了请告诉我......

任何人帮我绑定多个系列的1个图表...


My problem is the it always bind the "Series1".....Please let me know if I was doing anything wrong...
Anybody help me to bind 1 Chart with multiple series...

推荐答案

您的代码是正确的,代码中没有问题。如果在输出中没有看到Series2,则ObjectifTotal的值可能为零。检查从数据库中获得的值。



您的代码中的一个问题是您正在调用两次DataBind()方法,您只需要调用一次最后,删除额外的声明。 DataSource属性
Your code is correct, there is no issue in your code. If you don't see Series2 in the output, perhaps the value of ObjectifTotal is zero. Check the values that you get from the database.

One problem in your code is that you are calling DataBind() method twice, you need to call it only once at the end, remove the extra statement. Same is the case for DataSource property


这篇关于我需要帮助来绑定Asp.Net数据图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆