vba 在 Excel 中更改 X 轴比例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9848123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:37:41  来源:igfitidea点击:

Changing X axis scale in Excel

excelvba

提问by user1270123

I have a X-Y scatter plot, my values in the x axis starts from the value 30.

我有一个 XY 散点图,我在 x 轴上的值从值 30 开始。

How can i change the scale in the chart in such a way that I have values in the X axis starting from 30 and not zero?

如何更改图表中的比例,使 X 轴上的值从 30 开始而不是零?

回答by rrs

I was able to do this in VBA as follows:

我能够在 VBA 中做到这一点,如下所示:

  1. grab the chart object:

    Dim objChart As Object
    Set objChart = Sheets("MyWorksheetName").ChartObjects("MyChartName")
    
  2. change the x-axis min value:

    objChart.Chart.Axes(xlCategory).MinimumScale = myChartMinXValue
    
  1. 抓取图表对象:

    Dim objChart As Object
    Set objChart = Sheets("MyWorksheetName").ChartObjects("MyChartName")
    
  2. 更改 x 轴最小值:

    objChart.Chart.Axes(xlCategory).MinimumScale = myChartMinXValue
    

The x-axis in Excel charts seem to be called xlCategory. Also NOTE the MinimumScaleproperty doesn't exist for all chart types. My first attempt was using xlLinebut I kept getting an error. Once I switched to xlXYScatterLinesVBA was happy.

Excel 图表中的 x 轴似乎被称为xlCategory. 另请注意,MinimumScale并非所有图表类型都存在该属性。我的第一次尝试是使用,xlLine但我一直收到错误消息。一旦我切换到xlXYScatterLinesVBA 很高兴。

回答by brettdj

  • right click the x-axis
  • select Format Axis
  • select the Fixedoption next to Minimumand enter 30
  • 右键单击 x 轴
  • 选择 Format Axis
  • 选择Fixed旁边的选项Minimum并输入 30