简体   繁体   English

如何显示LineChart控件ASP.NET?

[英]How do I display a LineChart control ASP.NET?

I would like to display a Line Chart depending of the DropDownList control. 我想根据DropDownList控件显示一个折线图。

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. 当我选择此DropDown的值时,将显示折线图,其中包含我的值列组的平均值乘以我的DropDown的值。

The column Entite is a Varchar type and AvancementQuantitatifT1 is a decimal (3,2) type. Entite列是Varchar类型,而AvancementQuantitatifT1列是十进制(3,2)类型。

Nothing display when I choose a value of my DropDownList. 当我选择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. 我的SQL查询在SQL Management Studio中工作正常。

EDIT 编辑

Screenshot of my dt table : http://i.stack.imgur.com/VotIt.png 我的dt表的屏幕截图: 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). 并检查DataTable dt包含记录(在string[] x = new string[dt.Rows.Count]行处插入断点,然后将光标移到dt并使用TableVisualization选项)。

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, 其余的将取决于这一重要步骤的结果(确保DataTable dt确实包含记录并且不为null ;根据您的屏幕快照,它似乎为null),Rgds,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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