我尝试创建一个 XY 散点图,以显示具有每个钻孔的给定 XY 坐标的爆炸装药图。然后我尝试用下面的 VBA 代码标记每个孔号;
Sub Create_Charge_Map()
Dim ochartObj As ChartObject
Dim oChart As Chart
Worksheets("Charge_Map").Select
Set ochartObj = ActiveSheet.ChartObjects.Add(Top:=10, Left:=325, Width:=600, Height:=300)
Set oChart = ActiveSheet.ChartObjects(1).Chart
oChart.ChartType = xlXYScatter
'为每个孔设置一个源数据以显示它们的 xy 坐标'
oChart.SetSourceData Source:=Range("C14:D4500")
oChart.SeriesCollection.Add Source:=Range("J14:J4500")
oChart.SeriesCollection.Add Source:=Range("M14:M4500")
oChart.SeriesCollection.Add Source:=Range("P14:P4500")
oChart.SeriesCollection.Add Source:=Range("S14:S4500")
oChart.SeriesCollection.Add Source:=Range("V14:V4500")
oChart.SeriesCollection.Add Source:=Range("Y14:Y4500")
oChart.SeriesCollection.Add Source:=Range("C14:D4500")
'设置 X 轴和 Y 轴的比例'
oChart.Axes(xlValue).Select
oChart.Axes(xlValue).MinimumScale = ActiveSheet.Range("T8").Value
oChart.Axes(xlValue).MaximumScale = ActiveSheet.Range("T9").Value
oChart.Axes(xlCategory).Select
oChart.Axes(xlCategory).MinimumScale = ActiveSheet.Range("S8").Value
oChart.Axes(xlCategory).MaximumScale = ActiveSheet.Range("S9").Value
'标注每个洞的洞号'
Dim HoleDataSeries As Series
Dim SingleCell As Range
Dim HoleList As Range
Dim HoleCounter As Integer
Dim FontSize As Range
HoleCounter = 1
Set FontSize = Range("AG2")
Set HoleList = Range("B14:B4500")
Set HoleDataSeries = ActiveSheet.ChartObjects(1).Chart.SeriesCollection(1)
ActiveChart.SetElement (msoElementDataLabelNone)
HoleDataSeries.HasDataLabels = True
For Each SingleCell In HoleList
HoleDataSeries.Points(HoleCounter).DataLabel.Text = SingleCell.Value
HoleCounter = HoleCounter + 1
Next SingleCell
ActiveChart.SeriesCollection(1).DataLabels.Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.ReadingOrder = xlLTR
.Position = xlLabelPositionCenter
.Orientation = xlHorizontal
.Font.Size = FontSize
.Font.Bold = True
End With
End Sub
但它似乎漏掉了 34 号洞(我使用的数据总共有 345 个洞;每个洞都显示出来,但只有一个洞 34)。
我不知道我做错了什么。