首页 > 解决方案 > Excel - 在拆分图表第二轴上强制显示 0

问题描述

我正在制作一些图表来表示汽车生产的一些成本的演变。它基于一些成本估算文件,一切都是通过简单的点击生成的。我的问题是显示辅助轴的“0”值...

如您所见,没有表示辅助轴的 0 值...如何强制显示?

这是创建图表的代码部分:

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
'creating main graph
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'Application.EnableEvents = False
ActiveSheet.Range("A1").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLineMarkers
ActiveChart.Parent.Name = ActiveSheet.Name & " Cumul Chart"

'define the size of the chart
With ActiveSheet.Shapes(ActiveSheet.Name & " Cumul Chart")
    .Top = Range("B15").Top
    .Left = Range("B15").Left
    .Height = Range("P15:P45").Height
    .Width = Range("B37:P45").Width
End With

'creating the 4 series
'Cumul Nb Cars
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "='" & ActiveSheet.Name & "'!$B$9"
ActiveChart.SeriesCollection(1).Values = "='" & ActiveSheet.Name & "'!$C$9:$N$9"
ActiveChart.SeriesCollection(1).XValues = "='" & ActiveSheet.Name & "'!$C$3:$N$3"

'Cumul est Nb Cars
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "='" & ActiveSheet.Name & "'!$B$10"
ActiveChart.SeriesCollection(2).Values = "='" & ActiveSheet.Name & "'!$C$10:$N$10"
ActiveChart.SeriesCollection(2).XValues = "='" & ActiveSheet.Name & "'!$C$3:$N$3"

'Cumul price
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "='" & ActiveSheet.Name & "'!$B$11"
ActiveChart.SeriesCollection(3).Values = "='" & ActiveSheet.Name & "'!$C$11:$N$11"
ActiveChart.SeriesCollection(3).XValues = "='" & ActiveSheet.Name & "'!$C$3:$N$3"

'Cumul est price
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(4).Name = "='" & ActiveSheet.Name & "'!$B$12"
ActiveChart.SeriesCollection(4).Values = "='" & ActiveSheet.Name & "'!$C$12:$N$12"
ActiveChart.SeriesCollection(4).XValues = "='" & ActiveSheet.Name & "'!$C$3:$N$3"

'changing the 2 series to the second axis
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
ActiveChart.SeriesCollection(4).Select
ActiveChart.SeriesCollection(4).AxisGroup = 2

'Changing the axis max and min values to have the data visibles
ActiveChart.Axes(xlValue, xlSecondary).Select
ActiveChart.Axes(xlValue, xlSecondary).MinimumScale = -1 * (ActiveChart.Axes(xlValue, xlSecondary).MaximumScale + 0.1 * WorksheetFunction.Max(Range("n10").Value, Range("N12").Value))
ActiveChart.Axes(xlValue, xlSecondary).MaximumScale = Round(((ActiveChart.Axes(xlValue, xlSecondary).MaximumScale + 0.1 * WorksheetFunction.Max(Range("n10").Value, Range("N12").Value))) / 1000, 0) * 1000
Selection.TickLabels.NumberFormat = "0;;0"       'I guess this will have to be modified?
ActiveChart.Axes(xlValue).Select
ActiveChart.Axes(xlValue).MaximumScale = 2 * ActiveChart.Axes(xlValue).MaximumScale + 20
ActiveChart.Axes(xlValue).MinimumScale = 0
Selection.TickLabels.NumberFormat = "[<301];"
ActiveChart.SetElement (msoElementDataTableWithLegendKeys)


'then, there is some formatting, colours, title etc

那么,是不是可以强制两边都显示0呢?

提前致谢

标签: excelvbacharts

解决方案


推荐阅读