Spire.XLS如何在Excel利用多列数据创建组合图表

作者:控件中国网   出处:控件中国网   2015-08-27 14:42:55   阅读:5

Spire.XLS是一款可以实现类似Excel功能的文档处理类控件,几乎所有Excel的功能,利用Spire.XLS都可以实现并且操作简单,还可以提供很多自定义功能,组合图表在Excel中应用十分广泛,可以利用组合图表可视化地对Excel数据进行展示和多列数据的直观比较,具体使用可以参考下面的代码:

Workbook workbook = new Workbook();
workbook.LoadFromFile("data.xlsx");         
Worksheet sheet=workbook.Worksheets[0];

//add a chart based on the data from A1 to D5
Chart chart = sheet.Charts.Add();
chart.DataRange = sheet.Range["A1:D5"];
chart.SeriesDataFromRange = false;       

//set position of chart
chart.LeftColumn = 6;
chart.TopRow = 1;
chart.RightColumn = 12;
chart.BottomRow = 13;

//apply different chart type to different series
var cs1 = (ChartSerie)chart.Series[0];
cs1.SerieType = ExcelChartType.ColumnClustered;
var cs2 = (ChartSerie)chart.Series[1];
cs2.SerieType = ExcelChartType.ColumnClustered;     
var cs3 = (ChartSerie)chart.Series[2];
cs3.SerieType = ExcelChartType.LineMarkers;

//add a secondary axis to chart
chart.SecondaryCategoryAxis.IsMaxCross = true;
cs3.UsePrimaryAxis = false;

//save and launch the file
workbook.SaveToFile("result.xlsx");
System.Diagnostics.Process.Start("Sample.xlsx");

Create_Combination_2.png

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat