我有一个有两个线形图系列的图表。它们画得很好,但我想把其中一个放在次要的Y轴上。
这是我的代码(在VB。. Net,但c#响应很好):
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
我想在次要Y轴上绘制视图系列。我没有尝试建立和分配次级轴,因为我找不到适用于该步骤的任何属性。
好了,我明白了。
Dim destinationChart As ExcelChart = newWorksheet.Drawings.AddChart("AdStats", sourceChart.ChartType)
destinationChart.SetPosition(18, 0, 3, 0)
destinationChart.SetSize(800, 500)
destinationChart.PlotArea.ChartTypes.Add(eChartType.LineMarkers)
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
destinationChart.UseSecondaryAxis = True
解决方案是添加第四行和最后一行:destinationChart.PlotArea.ChartTypes.Add (eChartType.LineMarkers)和destinationChart。UseSecondaryAxis = True