How to add multiple y values from list box in to my line chart


  • I have a list box where I can select multiple values and I have a line chart where I want to display Time on the x-axis and the values of the list box in the y-axis. The y values are passed as my stored procedure in database and then the values are retrieved and displayed on the chart. So if the user chooses multiple values from the listbox, the graph will have multiple lines each representing one value in the listbox. Currently I am able to get one value(one y-axis set of data) but whenever I try to select two or more y values, the following error pops up. Please guide me how to get this. This is my first time working with charts!


      Message=Data points insertion error. Only 1 Y values can be set for this data series.
    Parameter name: dataSource"

    Below is my code

            protected void btnDisplayChart_Click(object sender, EventArgs e)
                SqlCommand cmd = new SqlCommand(s, con);

                cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = lb.SelectedValue;


                SqlDataReader rdr = cmd.ExecuteReader();

                chart1.Series["Series1"].XValueMember = "Time";
                chart1.Series["Series1"].YValueMembers = lb.SelectedValue;      

                chart1.DataSource = rdr;

                chart1.Visible = true;

    • Diedit oleh tkhan17 Senin, 23 Juli 2018 18.08
    • Dipindahkan oleh CoolDadTxMVP Senin, 23 Juli 2018 18.10 ASP.NET related
    Senin, 23 Juli 2018 17.18

Semua Balasan