Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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.
Posted
v2

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();
}
 
Share this answer
 
chart1.DAtaSource =da

change the above line

chart1.DataSource=ds.tables[0];

I solved it my self
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900