How to add multiple y values from list box in ASP.NET to my line chart RRS feed

  • Question

  • User-1262319794 posted

    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"

    What I have tried:

    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;
    Monday, July 23, 2018 6:04 PM

All replies