Spire.XLS 11.10.5已发布。本次更新主要新增了一些实用图表,比如瀑布图、排列图和直方图等等。详情请阅读以下内容。
新功能:
- 支持瀑布图、排列图、直方图、箱型图、树状图、旭日图以及漏斗图
Workbook workbook = new Workbook();
workbook.LoadFromFile("waterfall_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as waterfall
officeChart.ChartType = ExcelChartType.WaterFall;
//Set data range to the chart from the worksheet
officeChart.DataRange = sheet["A2:B8"];
//Data point settings as total in chart
officeChart.Series[0].DataPoints[3].SetAsTotal = true;
officeChart.Series[0].DataPoints[6].SetAsTotal = true;
//Showing the connector lines between data points
officeChart.Series[0].Format.ShowConnectorLines = true;
//Set the chart title
officeChart.ChartTitle = "Company Profit (in USD)";
//Formatting data label and legend option
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
officeChart.Legend.Position = LegendPositionType.Right;
workbook.SaveToFile("waterfall_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Pareto_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Pareto
officeChart.ChartType = ExcelChartType.Pareto;
//Set data range in the worksheet
officeChart.DataRange = sheet["A2:B8"];
//Set category values as bin values
officeChart.PrimaryCategoryAxis.IsBinningByCategory = true;
officeChart.PrimaryCategoryAxis.OverflowBinValue = 5;
officeChart.PrimaryCategoryAxis.UnderflowBinValue = 1;
//Formatting Pareto line
officeChart.Series[0].ParetoLineFormat.LineProperties.Color = System.Drawing.Color.Blue;
//Gap width settings
officeChart.Series[0].DataFormat.Options.GapWidth = 6;
//Set the chart title
officeChart.ChartTitle = "Expenses";
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Pareto_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Histogram_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as histogram
officeChart.ChartType = ExcelChartType.Histogram;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:A15"];
//Category axis bin settings
officeChart.PrimaryCategoryAxis.BinWidth = 8;
//Gap width settings
officeChart.Series[0].DataFormat.Options.GapWidth = 6;
//Set the chart title and axis title
officeChart.ChartTitle = "Height Data";
officeChart.PrimaryValueAxis.Title = "Number of students";
officeChart.PrimaryCategoryAxis.Title = "Height";
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Histogram_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Boxandwhisker_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set the chart title
officeChart.ChartTitle = "Yearly Vehicle Sales";
//Set chart type as Box and Whisker
officeChart.ChartType = ExcelChartType.BoxAndWhisker;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:E17"];
//Box and Whisker settings on first series
var seriesA = officeChart.Series[0];
seriesA.DataFormat.ShowInnerPoints = false;
seriesA.DataFormat.ShowOutlierPoints = true;
seriesA.DataFormat.ShowMeanMarkers = true;
seriesA.DataFormat.ShowMeanLine = false;
seriesA.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.ExclusiveMedian;
//Box and Whisker settings on second series
var seriesB = officeChart.Series[1];
seriesB.DataFormat.ShowInnerPoints = false;
seriesB.DataFormat.ShowOutlierPoints = true;
seriesB.DataFormat.ShowMeanMarkers = true;
seriesB.DataFormat.ShowMeanLine = false;
seriesB.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.InclusiveMedian;
//Box and Whisker settings on third series
var seriesC = officeChart.Series[2];
seriesC.DataFormat.ShowInnerPoints = false;
seriesC.DataFormat.ShowOutlierPoints = true;
seriesC.DataFormat.ShowMeanMarkers = true;
seriesC.DataFormat.ShowMeanLine = false;
seriesC.DataFormat.QuartileCalculationType = ExcelQuartileCalculation.ExclusiveMedian;
workbook.SaveToFile("Boxandwhisker_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("treemap_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as TreeMap
officeChart.ChartType = ExcelChartType.TreeMap;
//Set data range in the worksheet
officeChart.DataRange = sheet["A2:C11"];
//Set the chart title
officeChart.ChartTitle = "Area by countries";
//Set the Treemap label option
officeChart.Series[0].DataFormat.TreeMapLabelOption = ExcelTreeMapLabelOption.Banner;
//Formatting data labels
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
workbook.SaveToFile("treemap_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sunburst_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Sunburst
officeChart.ChartType = ExcelChartType.SunBurst;
//Set data range in the worksheet
officeChart.DataRange = sheet["A1:D16"];
//Set the chart title
officeChart.ChartTitle = "Sales by annual";
//Formatting data labels
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
//Hiding the legend
officeChart.HasLegend = false;
workbook.SaveToFile("Sunburst_chart.xlsx");
Workbook workbook = new Workbook();
workbook.LoadFromFile("Funnel_sample.xlsx");
var sheet = workbook.Worksheets[0];
var officeChart = sheet.Charts.Add();
//Set chart type as Funnel
officeChart.ChartType = ExcelChartType.Funnel;
//Set data range in the worksheet
officeChart.DataRange = sheet.Range["A1:B6"];
//Set the chart title
officeChart.ChartTitle = "Funnel";
//Formatting the legend and data label option
officeChart.HasLegend = false;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
officeChart.Series[0].DataPoints.DefaultDataPoint.DataLabels.Size = 8;
workbook.SaveToFile("Funnel_chart.xlsx");
下载Spire.XLS 11.10.5请点击: