在Visual Studio 2010中将数据绑定到图表控件的问题 [英] problem in binding data to chart control in visual studios 2010

查看:73
本文介绍了在Visual Studio 2010中将数据绑定到图表控件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void chart()
    {
        SqlConnection con = new SqlConnection(gps_conn);
        con.Open();
        string query = "select time_stamp,sensor2_1 from imei_352848026619078 where time_stamp between '"+fromtxt.Text+"' and '"+totxt.Text+"' order by time_stamp asc";
        SqlDataAdapter da = new SqlDataAdapter(query, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Chart1.DataSource = da;
        Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Time_stamp";
        Chart1.ChartAreas["ChartArea1"].AxisY.Title="Liters";
        Chart1.Series["Series1"].XValueMember = "time_stamp";
        Chart1.Series["Series1"].YValueMembers = "sensor2_1";
        Chart1.DataBind();
        da.Dispose();
        con.Close();
    }



我写了上面的代码来将数据绑定到图表。但数据并未绑定到图表。请改进上面的代码并给我解决方案。


I wrote above code to bind data to chart. But data is not binding to chart. Please improve the above code and give me the solution.

推荐答案

dost ...



public void chart()

{

SqlConnection con = new SqlConnection(gps_conn);

con.Open();

string query =select time_stamp,sensor2_1 from imei_352848026619078其中time_stamp介于''+ fromtxt.Text +''和''+ totxt.Text +''order by time_stamp asc;

SqlDataAdapter da = new SqlDataAdapter(query,con);

DataSet ds = new DataSet();

da.Fill(ds);

Chart1.DataSource = ds.Tables [0]; //在这里,您需要使用它(ds.Tables [0])而不是da。

Chart1.ChartAreas [ChartArea1]。 AxisX.Title =Time_stamp;

Chart1.ChartAreas [ChartArea1]。AxisY.Title =Liters;

Chart1.Series [Series1]。 XValueMember =time_stamp;

Chart1.Series [Ser ies1]。YValueMembers =sensor2_1;

Chart1.DataBind();

da.Dispose();

con.Close( );

}
Hi, dost...

public void chart()
{
SqlConnection con = new SqlConnection(gps_conn);
con.Open();
string query = "select time_stamp,sensor2_1 from imei_352848026619078 where time_stamp between ''"+fromtxt.Text+"'' and ''"+totxt.Text+"'' order by time_stamp asc";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
Chart1.DataSource = ds.Tables[0];// here, you need to use it( ds.Tables[0]) instead of da.
Chart1.ChartAreas["ChartArea1"].AxisX.Title = "Time_stamp";
Chart1.ChartAreas["ChartArea1"].AxisY.Title="Liters";
Chart1.Series["Series1"].XValueMember = "time_stamp";
Chart1.Series["Series1"].YValueMembers = "sensor2_1";
Chart1.DataBind();
da.Dispose();
con.Close();
}


chart1.DAtaSource = da



更改以上行



chart1.DataSource = ds.tables [0];



我自己解决了
chart1.DAtaSource =da

change the above line

chart1.DataSource=ds.tables[0];

I solved it my self


这篇关于在Visual Studio 2010中将数据绑定到图表控件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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