前面我们介绍了如何使用spire.xls 创建散点图表,该文将介绍如何使用c#、vb.net创建excel气泡图表。
c#
using spire.xls;
namespace bubblechart
{
class program
{
static void main(string[] args)
{
//创建工作簿
workbook workbook = new workbook();
//添加工作表并设置名称
workbook.createemptysheets(1);
worksheet sheet = workbook.worksheets[0];
sheet.name = "sample";
//创建气泡图表
chart chart = sheet.charts.add(excelcharttype.bubble);
//指定图表所在位置
chart.leftcolumn = 1;
chart.rightcolumn = 10;
chart.toprow = 1;
chart.bottomrow = 20;
//设置图表的名称和数据
spire.xls.charts.chartserie cs1 = chart.series.add("气泡图表");
cs1.entereddirectlyvalues = new object[] { 2.2, 5.6 };
cs1.entereddirectlycategorylabels = new object[] { 1.1, 4.4 };
cs1.entereddirectlybubbles = new object[] { 3, 6 };
//文档保存
workbook.savetofile("output.xlsx", excelversion.version2010);
}
}
}
vb.net
imports spire.xls
namespace bubblechart
class program
private shared sub main(byval args() as string)
'创建工作簿
dim workbook as workbook = new workbook
'添加工作表并设置名称
workbook.createemptysheets(1)
dim sheet as worksheet = workbook.worksheets(0)
sheet.name = "chart data"
'创建气泡图表
dim chart as chart = sheet.charts.add(excelcharttype.bubble)
'指定图表所在位置
chart.leftcolumn = 1
chart.rightcolumn = 10
chart.toprow = 1
chart.bottomrow = 20
'设置图表的名称和数据
dim cs1 as spire.xls.charts.chartserie = chart.series.add("气泡图表")
cs1.entereddirectlyvalues = new object() {2.2, 5.6}
cs1.entereddirectlycategorylabels = new object() {1.1, 4.4}
cs1.entereddirectlybubbles = new object() {3, 6}
'文档保存
workbook.savetofile("output.xlsx", excelversion.version2010)
end sub
end class
end namespace
气泡图表效果图: