我正在寻找创建一个散点图,在按下按钮时,它会在其中创建一个散点图Sheet 1
并A2:A11
用作x
值和B2:B11
值y
。
A1:B3
使用底部的代码允许我根据(从此处获取)中的值创建散点图。它很接近,但不完全是我想要的。我怎样才能调整它以满足我的需要?
我现在已经设置好了,所以图表是根据我想要的值制作的,但我不能让它在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