使用C#语言在Visual Studio 2019环境下,利用Chart控件实现圆饼图百分比的展示,可视化效果直观。以下是实现方法:

// 添加命名空间
using System.Windows.Forms.DataVisualization.Charting;

// 创建Chart对象
Chart chart1 = new Chart();

// 设置图表区域的位置和大小
chart1.ChartAreas.Add("ChartArea1");
chart1.ChartAreas["ChartArea1"].Position.X = 0;
chart1.ChartAreas["ChartArea1"].Position.Y = 0;
chart1.ChartAreas["ChartArea1"].Position.Width = 100;
chart1.ChartAreas["ChartArea1"].Position.Height = 100;

// 添加数据
chart1.Series.Add("Series1");
chart1.Series["Series1"].ChartType = SeriesChartType.Pie;
chart1.Series["Series1"].Points.AddXY("Apple", 30);
chart1.Series["Series1"].Points.AddXY("Banana", 20);
chart1.Series["Series1"].Points.AddXY("Orange", 50);

// 设置标签
chart1.Series["Series1"].IsValueShownAsLabel = true;
chart1.Series["Series1"].Label = "#PERCENT{P0}";

// 添加Chart控件到窗体中
this.Controls.Add(chart1);

源代码解释可参考博客:https://blog.csdn.net/hgaohr1021/article/details/129023432