前面我们介绍了如何使用Spire.XLS创建各类Excel图表,本文将介绍如何使用Spire.XLS制作 Excel 分离型饼图和分离型环形图。
分离型饼状图(Exploded Pie Chart)饼图分离有两种方式,设置饼图整体分离程度和单一数据点爆炸型。我们将从下面两个方面将饼图分离。
整体分离饼图
C#
Workbook workbook = new Workbook();
workbook.LoadFromFile("PieChart.xlsx");
Worksheet ws = workbook.Worksheets[0];
Chart chart = ws.Charts[0];
for (int i = 0; i < chart.Series.Count; i++)
{
chart.Series[i].DataFormat.Percent = 20;
}
workbook.SaveToFile("ExplodePieChart.xlsx", FileFormat.Version2013);
VB.NET
Dim workbook As New Workbook()
workbook.LoadFromFile("PieChart.xlsx")
Dim ws As Worksheet = workbook.Worksheets(0)
Dim chart As Chart = ws.Charts(0)
For i As Integer = 0 To chart.Series.Count - 1
chart.Series(i).DataFormat.Percent = 20
Next
workbook.SaveToFile("ExplodePieChart.xlsx", FileFormat.Version2013)
部分分离饼图
C#
Workbook workbook = new Workbook();
workbook.LoadFromFile("PieChart.xlsx");
Worksheet ws = workbook.Worksheets[0];
Chart chart = ws.Charts[0];
chart.Series[0].DataPoints[1].DataFormat.Percent = 20;
workbook.SaveToFile("ExplodePieChart2.xlsx", FileFormat.Version2013);
VB.NET
Dim workbook As New Workbook()
workbook.LoadFromFile("PieChart.xlsx")
Dim ws As Worksheet = workbook.Worksheets(0)
Dim chart As Chart = ws.Charts(0)
chart.Series(0).DataPoints(1).DataFormat.Percent = 20
workbook.SaveToFile("ExplodePieChart2.xlsx", FileFormat.Version2013)
分离型环形图(Exploded Doughnut Chart)
C#
//加载Excel文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("DoughnutChart.xlsx", ExcelVersion.Version2010);
//获取第一个工作表
Worksheet sheet = workbook.Worksheets[0];
//获取第一个工作表里的第一个图表
Chart chart = sheet.Charts[0];
//将图表类型设置为分离型环形图
chart.ChartType = ExcelChartType.DoughnutExploded;
//保存Excel文档
workbook.SaveToFile("ExplodedDoughnutChart.xlsx", ExcelVersion.Version2010);
VB.NET
'加载Excel文档
Dim workbook As New Workbook()
workbook.LoadFromFile("DoughnutChart.xlsx", ExcelVersion.Version2010)
'获取第一个工作表
Dim sheet As Worksheet = workbook.Worksheets(0)
'获取第一个工作表里的第一个图表
Dim chart As Chart = sheet.Charts(0)
'将图表类型设置为分离型环形图
chart.ChartType = ExcelChartType.DoughnutExploded
'保存Excel文档
workbook.SaveToFile("ExplodedDoughnutChart.xlsx", ExcelVersion.Version2010)