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

  • Question

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

    • Edited by tkhan17 Monday, July 23, 2018 6:08 PM
    • Moved by CoolDadTx Monday, July 23, 2018 6:10 PM ASP.NET related
    Monday, July 23, 2018 5:18 PM

All replies

  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, July 23, 2018 6:10 PM