本文将介绍通过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)
图表效果: