Excel.Chart xlChart = (Excel.Chart)ThisWorkbook.Charts.Add(Missing.Value, XlSheet, Missing.Value, Missing.Value);
Excel.Range cellRange = (Excel.Range)XlSheet.Cells[1, 1]; // 從 A1 開始
xlChart.ChartWizard(
cellRange.CurrentRegion,
Excel.XlChartType.xl3DColumn, Missing.Value,
Excel.XlRowCol.xlColumns, 1, 0, true,
"訪問量比較", "月份", "訪問量", "");
// Sheet 名稱
xlChart.Name = "統計";
// 圖表組
Excel.ChartGroup grp = (Excel.ChartGroup)xlChart.ChartGroups(1);
grp.GapWidth = 20;
grp.VaryByCategories = true; // 單系列逐點著色
// 系列
Excel.Series s = (Excel.Series)grp.SeriesCollection(1);
s.BarShape = Excel.XlBarShape.xlCylinder; // 圓柱
s.HasDataLabels = true; // 數值標簽
// 圖例位置
xlChart.Legend.Position = Excel.XlLegendPosition.xlLegendPositionTop;
// 標題樣式
xlChart.ChartTitle.Font.Size = 24;
xlChart.ChartTitle.Shadow = true;
xlChart.ChartTitle.Border.LineStyle = Excel.XlLineStyle.xlContinuous;
配置雙軸屬性(標題方向、字體)、完整保存導出代碼、最終效果截圖。