1 private void Form2_Load(object sender, EventArgs e) 2 { 3 chart1.Series.Clear(); //清除默认的Series 4 Series Strength = new Series("力量"); //new 一个叫做【Strength】的系列 5 Strength.ChartType = SeriesChartType.Pie; //设置chart的类型 pie饼状图 6 //Strength.IsValueShownAsLabel = true; //把值当做标签展示(默认false) 7 //chart1.Series["series1"].LegendText = "#VALX"; 8 Strength.Label = "#VALX:#PERCENT{P0}";//#VALX显示X轴信息,#PERCENT{P0}以百分比显示Y轴信息,{P0}保留0位小数点 9 int[] arr = new int[] { 20, 20, 20, 40 }; 10 //给系列上的点进行赋值,分别对应横坐标和纵坐标的值 11 for (int i = 1; i <= arr.Length; i++) 12 { 13 Strength.Points.AddXY(i, arr[i - 1]); 14 } 15 Strength.Points[0].Color = Color.Yellow; //实现控制饼状图的颜色,改变对应下标的扇形的颜色 16 //把series添加到chart上 17 chart1.Series.Add(Strength); 18 }