Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
1.50/5 (3 votes)
See more:
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();

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...
Posted
Updated 3-Apr-14 9:39am
v2
Comments
Sergey Alexandrovich Kryukov 3-Apr-14 15:11pm    
Help with what? This is not a question. The problem is not explained...
—SA
ZurdoDev 3-Apr-14 20:49pm    
Where do you define the series?

1 solution

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