Excel VBA和图表。 Y轴标签问题

问题描述 投票:0回答:1

刚开始使用Excel和图表....

当前代码:

With excel_Chart.Chart
    .ChartType = xlColumnClustered
    .SeriesCollection.NewSeries
    .SeriesCollection(1).Values = _
            Array(numOfSmallHits, numOfAllHits, numOfTallHits)  'array_value
End With

生成这两个图表。当两个值均为1时,Y轴显示0,0.5,1,1.5

enter image description here

enter image description here

当一个值为1而另一个值为2时,Y轴显示0,1,2,3

我不想使用硬编码标签,因为这是一个动态图表,但我确实只想使用整数。我尝试这样做是通过在上面的代码片段中添加以下代码行。

  .Axes(xlValue).TickLabels.NumberFormat = "0"

首先,当值为1和2时,似乎没有任何变化。

enter image description here

但是当两个值碰巧都是1时,我在Y轴(0,1,1,2)上得到一个重复值。

enter image description here

对于动态图表,需要设置什么属性才能使整数以1为增量显示。例如,0,1,2,3,4,5 ....

excel vba charts label
1个回答
2
投票

我想你正在寻找Axis.MajorUnit的财产。

尝试:

.Axes(xlValue).MajorUnit = 1
© www.soinside.com 2019 - 2024. All rights reserved.