本文将介绍通过spire.xls for .net来创建excel雷达图表的方法。
c#
//实例化workbook类的对象,并获取第一个表格
workbook workbook = new workbook();
worksheet sheet = workbook.worksheets[0];
//添加表格数据
sheet.range["a1"].value = "部门";
sheet.range["a2"].value = "研发部";
sheet.range["a3"].value = "质检部";
sheet.range["a4"].value = "生产部";
sheet.range["a5"].value = "财务部";
sheet.range["a6"].value = "销售部";
sheet.range["b1"].value = "人数";
sheet.range["b2"].numbervalue = 30;
sheet.range["b3"].numbervalue = 10;
sheet.range["b4"].numbervalue = 25;
sheet.range["b5"].numbervalue = 28;
sheet.range["b6"].numbervalue = 20;
sheet.range["c1"].value = "月支出(万元)";
sheet.range["c2"].numbervalue = 60;
sheet.range["c3"].numbervalue = 45;
sheet.range["c4"].numbervalue = 50;
sheet.range["c5"].numbervalue = 38;
sheet.range["c6"].numbervalue = 65;
//格式化表格数据
sheet.range["a1:c1"].style.font.isbold = true;
sheet.range["a1:c6"].style.font.size = 12;
sheet.range["a1:c1"].rowheight = 17;
sheet.range["a1:c6"].columnwidth = 16;
sheet.range["a1:c1"].style.knowncolor = excelcolors.paleblue;
sheet.range["a2:c6"].style.knowncolor = excelcolors.lightyellow;
sheet.range["a1:c6"].style.horizontalalignment = horizontalaligntype.center;
sheet.range["b2:c6"].style.numberformat = "\"¥\"#,##0";
//添加雷达图表到表格
chart chart = sheet.charts.add(excelcharttype.radar);
chart.leftcolumn = 1;
chart.toprow = 7;
chart.rightcolumn = 8;
chart.bottomrow = 27;
chart.datarange = sheet.range["a1:c6"];
chart.seriesdatafromrange = false;
chart.charttitle = "部门开支统计分析";
chart.charttitlearea.isbold = true;
chart.charttitlearea.size = 12;
chart.plotarea.fill.visible = true;
chart.legend.position = legendpositiontype.corner;
//保存文档
workbook.savetofile("result.xlsx", excelversion.version2010);
vb.net
'实例化workbook类的对象,并获取第一个表格
dim workbook as new workbook()
dim sheet as worksheet = workbook.worksheets(0)
'添加表格数据
sheet.range("a1").value = "部门"
sheet.range("a2").value = "研发部"
sheet.range("a3").value = "质检部"
sheet.range("a4").value = "生产部"
sheet.range("a5").value = "财务部"
sheet.range("a6").value = "销售部"
sheet.range("b1").value = "人数"
sheet.range("b2").numbervalue = 30
sheet.range("b3").numbervalue = 10
sheet.range("b4").numbervalue = 25
sheet.range("b5").numbervalue = 28
sheet.range("b6").numbervalue = 20
sheet.range("c1").value = "月支出(万元)"
sheet.range("c2").numbervalue = 60
sheet.range("c3").numbervalue = 45
sheet.range("c4").numbervalue = 50
sheet.range("c5").numbervalue = 38
sheet.range("c6").numbervalue = 65
'格式化表格数据
sheet.range("a1:c1").style.font.isbold = true
sheet.range("a1:c6").style.font.size = 12
sheet.range("a1:c1").rowheight = 17
sheet.range("a1:c6").columnwidth = 16
sheet.range("a1:c1").style.knowncolor = excelcolors.paleblue
sheet.range("a2:c6").style.knowncolor = excelcolors.lightyellow
sheet.range("a1:c6").style.horizontalalignment = horizontalaligntype.center
sheet.range("b2:c6").style.numberformat = """¥""#,##0"
'添加雷达图表到表格
dim chart as chart = sheet.charts.add(excelcharttype.radar)
chart.leftcolumn = 1
chart.toprow = 7
chart.rightcolumn = 8
chart.bottomrow = 27
chart.datarange = sheet.range("a1:c6")
chart.seriesdatafromrange = false
chart.charttitle = "部门开支统计分析"
chart.charttitlearea.isbold = true
chart.charttitlearea.size = 12
chart.plotarea.fill.visible = true
chart.legend.position = legendpositiontype.corner
'保存文档
workbook.savetofile("result.xlsx", excelversion.version2010)
图表效果: