我想创建一个图表来获取我的观点并重复它们n次。
编辑:
一个段可以超过200K点,因此复制点n次的解决方案不正确!
结束编辑
例:
我的观点是(0,0),(1,1),(2,2),(3,1),(4,0)
它看起来像这样:
在VBA中,我需要重复所有这些点,使用X轴更改,n次以获得下一个结果:
编辑:
我的VBA代码:
Sub CreateChart()
'PURPOSE: Create a chart (chart dimensions are not required)
Dim rng1 As Range
Dim cht As Object
Dim aTitle As String
Dim bTitle As String
aTitle = Range("A1").Value
bTitle = Range("B1").Value
Range("A1").Clear
Range("B1").Clear
'Your data range for the chart
Set rng1 = ActiveSheet.Range("A2:B6")
'Create a chart
Set cht = ActiveSheet.Shapes.AddChart2
'Give chart some data
cht.Chart.SetSourceData Source:=rng1
'cht.Chart.SetSourceData Source:=rng1
'Determine the chart type
cht.Chart.ChartType = xlXYScatterLines
Range("A1").Value = aTitle
Range("B1").Value = bTitle
End Sub
答案 0 :(得分:0)
我感觉很好,所以这里会产生你需要的数据。您输入所需的数据点数,以及您希望数据左上角的单元格。
Sub TriangleWave(numPoints As Long, startCell As range)
Dim i As Long, j As Integer, increment As Integer
j = 0
increment = 1
For i = 0 To numPoints - 1
startCell.Offset(i, 0).value = i
startCell.Offset(i, 1).value = j
j = j + increment
If j = 2 Then
increment = -1
ElseIf j = 0 Then
increment = 1
End If
Next i
End Sub
Sub ExampleUsage()
TriangleWave 300000, range("TempData!A1")
End Sub
只需选择此数据并转到“插入”|图表|分散并选择实线散点图。