前面我们介绍了如何使用,本文将介绍如何使用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)