我期待创建散点图是,按下按钮,在
Excel的VBA:添加散点图到工作表对象Sheet 1
创建散点图和使用
A2:A11
作为
x
值和
B2:B11
为
y
值。
在底部使用代码允许我创建一个基于
A1:B3
(从
here得到这个值)的散点图。它接近,但不完全是我要找的。我如何调整这个以适应我的需求?
基于我想要的值,我现在已经设置好了图表,所以根据我想要的值创建了图表,但我无法在Sheet 1
中看到它作为对象出现。我该怎么做呢? .Location xlLocationAsObject
似乎不起作用。
Private Sub chartButton_Click()
ActiveWorkbook.Charts.Add
With ActiveWorkbook.ActiveChart
'Data?
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "=""Scatter Chart"""
.SeriesCollection(1).XValues = "=Sheet1!$A$2:$A$11"
.SeriesCollection(1).Values = "=Sheet1!$B$2:$B$11"
'Location
'DON'T KNOW WHAT TO PUT HERE
'.location xlLocationAsObject doesn't work!
'Titles
.HasTitle = True
.ChartTitle.Characters.Text = "Scatter Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X values"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y values"
.Axes(xlCategory).HasMajorGridlines = True
'Formatting
.Axes(xlCategory).HasMinorGridlines = False
.Axes(xlValue).HasMajorGridlines = True
.Axes(xlValue).HasMinorGridlines = False
.HasLegend = False
End With
End Sub