初学者在这里提问。我有一部分vba脚本获取数据(取决于用户以前的输入),并返回特定于相关数据的条形图。我正在寻找如何增加下面的代码,以提供一个恒定的x轴标签结构。我总是希望最小值为0,最大值为5.现在,我根据返回的数据得到定制的x轴标记。
其中一些可能是乱七八糟的混乱,并寻找任何方法来使这更有效或优雅。感谢。
'CREATE CHART WITH CURRENT
Dim chart_1 As Chart
'Chart
If Cells(16, 4).Value = "Data Not Available" Then
Range("A1").Select
Else
Set chart_1 = Charts.Add
Set chart_1 = chart_1.Location(Where:=xlLocationAsObject, Name:="LMC_Model")
'with statement to expedite typing
With chart_1
.HasTitle = True
.ChartTitle.Text = scenario & " Scores for " & risk
.ChartType = xlColumnClustered
'if statement to get correct data for x-axis
If scenario = current Then
.SetSourceData Source:=ThisWorkbook.Worksheets(riskLookupScore).Range("a2:a11, b2:b11"), PlotBy:=xlRows
ElseIf scenario = shortTerm Then
.SetSourceData Source:=ThisWorkbook.Worksheets(riskLookupScore).Range("a2:a11, c2:c11"), PlotBy:=xlRows
ElseIf scenario = longTerm Then
.SetSourceData Source:=ThisWorkbook.Worksheets(riskLookupScore).Range("a2:a11, d2:d11"), PlotBy:=xlRows
End If
With .Parent
.Height = 315
.Width = 440
.Top = Range("b26").Top
.Left = Range("b26").Left
.Name = "Bar Chart"
End With
End With
End If
答案 0 :(得分:1)
尝试
With chart_1.
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 5
End With