简体   繁体   中英

How do I display a LineChart control ASP.NET?

I would like to display a Line Chart depending of the DropDownList control.

When I choose a value of this DropDown, the Line Chart display with the average of my value column group by the value of my DropDown.

The column Entite is a Varchar type and AvancementQuantitatifT1 is a decimal (3,2) type.

Nothing display when I choose a value of my DropDownList.

This is my code behind :

 protected void entite_SelectedIndexChanged(object sender, EventArgs e)
        {
            string query = string.Format("select Entite, AVG(AvancementQuantitatifT1 * 100) FROM reponse WHERE Entite = '{0}' GROUP BY Entite", NomEntite.SelectedItem.Value);
            DataTable dt = GetData(query);

            string[] x = new string[dt.Rows.Count];
            decimal[] y = new decimal[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                x[i] = dt.Rows[i][0].ToString();
                y[i] = Convert.ToInt32(dt.Rows[i][1]);
            }
            LineChart1.Series.Add(new AjaxControlToolkit.LineChartSeries { Data = y });
            LineChart1.CategoriesAxis = string.Join(",", x);
            LineChart1.ChartTitle = string.Format("{0}", NomEntite.SelectedItem.Value);
            if (x.Length > 3)
            {
                LineChart1.ChartWidth = (x.Length * 75).ToString();
            }
            LineChart1.Visible = true;
        }

My SQL Query works fine in SQL Management studio.

EDIT

Screenshot of my dt table : http://i.stack.imgur.com/VotIt.png

First, modify/debug your query string:

string query = "SELECT Entite, AVG(AvancementQuantitatifT1 * 100) As AvrVal FROM reponse WHERE Entite = '" + (sender As ComboBox).Text + "' GROUP BY Entite") 

and check if DataTable dt contains records (insert a breakpoint at line string[] x = new string[dt.Rows.Count] , then move cursor over dt and use TableVisualization option).

Note: reponse - is it correct Table Name?

The rest will depend on the result of this important step (make sure that DataTable dt indeed contains records and is not null ; it seems that it's null based on your screenshot), Rgds,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM