Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a dynamic chart from a mysql database table, from selected columns.
I can graph 2 specific columns in a chart, but the problem I am having is when I try to change chart type.
I am getting this error:
a chart element with name series1 could not be found in the seriescollection


What I have tried:

public void GetData()
    {
        String constr = System.Configuration.ConfigurationManager.ConnectionStrings["web"].ToString();
        //MySqlConnection con = new MySqlConnection(constr);        
        using (MySqlConnection con = new MySqlConnection(constr))
        {
            MySqlCommand cmd = new MySqlCommand("select " + col1.Text + ", " + col2.Text + " from avance_actividad", con);
                Series series = Chart1.Series["Series1"];
            con.Open();
            MySqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                series.Points.AddXY(rdr[col1.Text].ToString(), rdr[col2.Text]);
                //this.Chart1.Series["Series1"].Points.AddXY(rdr.GetString(col1.Text), rdr.GetInt32(col2.Text));
            }
        }
    }

    protected void graph_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetData();
        this.Chart1.Series["Series1"].ChartType = (SeriesChartType)Enum.Parse(
                typeof(SeriesChartType), graph.SelectedValue);
    }
Posted
Updated 21-Dec-17 3:04am

1 solution

I just fixed it.
protected void graph_SelectedIndexChanged1(object sender, EventArgs e)
    {
        Chart1.Series.Clear();
        Chart1.Series.Add("Series1");
        GetData();
        this.Chart1.Series["Series1"].ChartType =
            (SeriesChartType)Enum.Parse(typeof(SeriesChartType),
                       graph.SelectedValue); 
    }
 
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