以编程方式填充 XYchart excel 图表?
Filling a XYchart excel chart programmatically?
我正在尝试向 excel 图表添加数据点,所以我基本上是这样写的:
'Assume that ChartXY is a XYchart object created in an Excel sheet
Dim i as interger
Dim chartXY as Object
set chartXY = ActiveSheet.ChartObjects(1) 'There's one chart.
Dim PointsX(0 To 3, 0 To 0) As Double
Dim PointsY(0 To 3, 0 To 0) As Double
For i = 0 to 3
PointsX (i,0)= i
PointsY (i,0)= i
Next
With ChartXY.SeriesCollection
If .Count = 0 then .NewSeries
Item(1).Xvalues = PointsX
Item(1).Yvalues = PointsY
End If
With End
好像不行?任何想法!
详细说明 Tim 的评论:您对项目 (1) 的两个引用需要在前面加一个点。
With ChartXY.Chart.SeriesCollection
If .Count = 0 then .NewSeries
.Item(1).Xvalues = PointsX
.Item(1).values = PointsY
End If
End With
这是我的问题的答案:
Assume that ChartXY is a XYchart object created in an Excel sheet
Dim i as interger
Dim chartXY as Object
set chartXY = ActiveSheet.ChartObjects(1) 'There's one chart.
Dim PointsX(0 To 3, 0 To 0) As Double
Dim PointsY(0 To 3, 0 To 0) As Double
For i = 0 to 3
PointsX (i,0)= i
PointsY (i,0)= i
Next
With ChartXY.SeriesCollection
If .Count = 0 then .NewSeries
Item(1).values = PointsX
Item(1).Xvalues = PointsY
End If
With End
我正在尝试向 excel 图表添加数据点,所以我基本上是这样写的:
'Assume that ChartXY is a XYchart object created in an Excel sheet
Dim i as interger
Dim chartXY as Object
set chartXY = ActiveSheet.ChartObjects(1) 'There's one chart.
Dim PointsX(0 To 3, 0 To 0) As Double
Dim PointsY(0 To 3, 0 To 0) As Double
For i = 0 to 3
PointsX (i,0)= i
PointsY (i,0)= i
Next
With ChartXY.SeriesCollection
If .Count = 0 then .NewSeries
Item(1).Xvalues = PointsX
Item(1).Yvalues = PointsY
End If
With End
好像不行?任何想法!
详细说明 Tim 的评论:您对项目 (1) 的两个引用需要在前面加一个点。
With ChartXY.Chart.SeriesCollection
If .Count = 0 then .NewSeries
.Item(1).Xvalues = PointsX
.Item(1).values = PointsY
End If
End With
这是我的问题的答案:
Assume that ChartXY is a XYchart object created in an Excel sheet
Dim i as interger
Dim chartXY as Object
set chartXY = ActiveSheet.ChartObjects(1) 'There's one chart.
Dim PointsX(0 To 3, 0 To 0) As Double
Dim PointsY(0 To 3, 0 To 0) As Double
For i = 0 to 3
PointsX (i,0)= i
PointsY (i,0)= i
Next
With ChartXY.SeriesCollection
If .Count = 0 then .NewSeries
Item(1).values = PointsX
Item(1).Xvalues = PointsY
End If
With End