create multiple y axis line chart in winforms

ravi kumar 331 Reputation points
2021-02-16T07:11:00.907+00:00

Dear all ,

Using this below sql stored procedure i want to create line chart with 3 line in my winforms app , but during execution i am getting this below error:
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

In the line:

Chrtline.Series[1].Points.DataBindXY(Datetable, Turningtable);  

kindly help me how to solve this , and what i am doing wrong:

my sql stored procedure:

@fromDate Date,  
@toDate Date  
as  
SELECT [Date],  
isnull([Milling],0)as [Milling],  
isnull([Turning],0) as [Turning],  
isnull([EDM],0) as [EDM] FROM (  
  SELECT  
    [Date],  
    Department,  
    Count(Action_Status) as Status  
  FROM Semicon_NPD  
  Where (Date between  @fromDate  and  @toDate) and (Action_Status = 'Pending')  
   group by Department,[Date]  
) StatusCount  
PIVOT (  
  SUM([Status])  
  FOR [Department]  
  IN (  
    [Milling],  
    [Turning],  
    [EDM]  
  )  
)  
 AS PivotTable  

my code for populating chart:

private void statusline()  
        {  
            SqlConnection con = new SqlConnection(cs);  
            SqlCommand cmd = new SqlCommand("statusline", con);  
            cmd.Parameters.AddWithValue("@fromDate", dtfrom.Value);  
            cmd.Parameters.AddWithValue("@toDate", dtto.Value);  
            cmd.CommandType = CommandType.StoredProcedure;  
            con.Open();  
            SqlDataReader dr = cmd.ExecuteReader();  
            while (dr.Read())  
            {  
                Datetable.Add(dr.GetDateTime(0));  
                Millingcount.Add(dr.GetInt32(1));  
                Turningtable.Add(dr.GetInt32(2));  
                EDMtable.Add(dr.GetInt32(3));  
  
            }  
            Chrtline.Series[0].Points.DataBindXY(Datetable, Millingcount);  
            Chrtline.Series[1].Points.DataBindXY(Datetable, Turningtable);  
            Chrtline.Series[2].Points.DataBindXY(Datetable, EDMtable);  
            dr.Close();  
            con.Close();  
        }  

example result set:
68566-image.png

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,236 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
{count} votes