You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用EPPlus 6.1.3,如何将图表系列分配至次Y轴?

如何将Excel图表系列指定到次Y轴

现有VB.Net代码生成包含两个折线图系列的Excel图表,需将Views系列移至次Y轴显示:

Dim destinationChart As ExcelChart = newWorksheet.Drawings.AddChart("AdStats", sourceChart.ChartType)
destinationChart.SetPosition(18, 0, 3, 0)
destinationChart.SetSize(800, 500)

Dim Views As ExcelChartSerie = destinationChart.Series.Add("B18:B31", "A18:A31")
Views.Header = newWorksheet.Cells(17, 2).Value

Dim Inquiries As ExcelChartSerie = destinationChart.Series.Add("C18:C31", "A18:A31")
Inquiries.Header = newWorksheet.Cells(17, 3).Value

解决方案(VB.Net)

只需两步:启用次Y轴,将目标系列关联到次Y轴:

Dim destinationChart As ExcelChart = newWorksheet.Drawings.AddChart("AdStats", sourceChart.ChartType)
destinationChart.SetPosition(18, 0, 3, 0)
destinationChart.SetSize(800, 500)

Dim Views As ExcelChartSerie = destinationChart.Series.Add("B18:B31", "A18:A31")
Views.Header = newWorksheet.Cells(17, 2).Value
' 将Views系列指定到次Y轴
Views.AxisGroup = eAxisGroup.Secondary
' 确保次Y轴可见
destinationChart.Axes(eAxisType.Value, eAxisGroup.Secondary).Visible = True

Dim Inquiries As ExcelChartSerie = destinationChart.Series.Add("C18:C31", "A18:A31")
Inquiries.Header = newWorksheet.Cells(17, 3).Value

对应C#实现

ExcelChart destinationChart = newWorksheet.Drawings.AddChart("AdStats", sourceChart.ChartType);
destinationChart.SetPosition(18, 0, 3, 0);
destinationChart.SetSize(800, 500);

ExcelChartSerie Views = destinationChart.Series.Add("B18:B31", "A18:A31");
Views.Header = newWorksheet.Cells[17, 2].Value;
// 将Views系列指定到次Y轴
Views.AxisGroup = eAxisGroup.Secondary;
// 确保次Y轴可见
destinationChart.Axes(eAxisType.Value, eAxisGroup.Secondary).Visible = true;

ExcelChartSerie Inquiries = destinationChart.Series.Add("C18:C31", "A18:A31");
Inquiries.Header = newWorksheet.Cells[17, 3].Value;

注:上述代码基于EPPlus库的API规范,若你使用的是其他Excel操作库,属性名(如AxisGroup、eAxisGroup)可能略有差异,但核心逻辑一致:为目标系列设置次坐标轴分组,并启用次Y轴显示。

内容的提问来源于stack exchange,提问作者George Harrison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 17:45:14