chart绑定数据库,统计分数优良中差的人数,最后以饼图展示

想实现如下功能:
用.net的chart控件绑定数据库,从数据表中统计表中分数为优、良、中、差的人数分别为多少,最后以饼图展示结果
求各位帮帮忙,谢谢!

小魔女参考了bing和GPT部分内容调写:
使用.net Chart控件来绑定数据库,从数据库中统计出优、良、中、差各个分数段的人数,最后用饼图的形式展示出来。

步骤如下:

1、在项目中引用System.Web.DataVisualization.dll,并添加Chart控件到页面中;

2、连接数据库,并读取对应表中的数据;

3、使用Linq语句统计出优、良、中、差各个分数段的人数并存入一个List集合中;

4、将List集合绑定到Chart控件上;

5、设置Chart的图表类型为饼图;

6、将Chart控件添加到页面中。

C# //1.引用System.Web.DataVisualization.dll using System.Web.DataVisualization; //2.连接数据库 SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Test;User ID=sa;Password=123456"); conn.Open(); //3.读取对应表中的数据 string sql = "select score from student"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader dr = cmd.ExecuteReader(); //4.使用Linq语句统计出优、良、中、差各个分数段的人数并存入一个List集合中 List<int> list = new List<int>(); while (dr.Read()) { int score = Convert.ToInt32(dr["score"]); if (score >= 90) { list[0]++; } else if (score >= 80 && score < 90) { list[1]++; } else if (score >= 70 && score < 80) { list[2]++; } else { list[3]++; } } //5.将List集合绑定到Chart控件上 Chart1.Series[0].Points.DataBindY(list); //6.设置Chart的图表类型为饼图 Chart1.Series[0].ChartType = SeriesChartType.Pie; //7.将Chart控件添加到页面中 this.Controls.Add(Chart1);
回答不易,记得采纳呀。