如何显示LineChart控件ASP.NET?

时间:2014-06-28 15:21:43

标签: c# asp.net

我想根据DropDownList控件显示折线图。

当我选择此DropDown的值时,折线图显示我的值列组的平均值与我的DropDown的值。

列Entite是Varchar类型,AvancementQuantitatifT1是十进制(3,2)类型。

当我选择DropDownList的值时,什么都不显示。

这是我背后的代码:

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

我的SQL查询在SQL Management studio中运行良好。

修改

我的dt表的屏幕截图:http://i.stack.imgur.com/VotIt.png

1 个答案:

答案 0 :(得分:0)

首先,修改/调试查询字符串:

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

并检查DataTable dt是否包含记录(在行string[] x = new string[dt.Rows.Count]处插入断点,然后将光标移到dt上并使用TableVisualization选项)。

注意:响应 - 表名是否正确?

其余的将取决于这一重要步骤的结果(确保DataTable dt确实包含记录而不是null;根据您的屏幕截图,它似乎为空), RGDS,