I doubt getting data from cells is what's slowing things down. Following
makes a chart with 5 x 1000xy series (ie 10k data cells) pretty quickly,
even in Excel 2007 it took less than 0.5 sec (in an old system), and most of
that time was running the last line to reset screenupdating.
Option Explicit
Sub SpiralTest()
Dim xA As Double, yA As Double
Dim xK As Double, yK As Double
Dim pts As Long
Dim rad As Double, rdn As Double
Dim nS As Long
Dim arr() As Double
Dim rng As Range
Dim cht As Chart
On Error Resume Next
' << just for testing >>
ActiveSheet.ChartObjects.Delete
ActiveSheet.UsedRange.ClearContents
On Error GoTo 0
Application.ScreenUpdating = False
Set cht = ActiveSheet.ChartObjects.Add(10, 10, 300, 600).Chart
cht.ChartType = xlXYScatterSmoothNoMarkers
cht.HasLegend = False
rdn = Application.WorksheetFunction.Pi / 180
pts = 1080
rad = 1
ReDim arr(1 To pts, 1 To 2)
For nS = 1 To 5
If nS = 1 Then
xA = 0: yA = -40: xK = 3: yK = 6
ElseIf nS = 2 Then
xA = 0: yA = 0: xK = 6: yK = 6
ElseIf nS = 3 Then
xA = 0: yA = -20: xK = 6: yK = 4
ElseIf nS = 4 Then
xA = 0: yA = 20: xK = 6: yK = 18
ElseIf nS = 5 Then
xA = 0: yA = 40: xK = 6: yK = 30
End If
MakeSpiral rdn, rad, pts, xA, yA, xK, yK, arr
Set rng = ActiveSheet.Cells(1, nS * 2 - 1).Resize(pts, 2)
rng.Value = arr
With cht.SeriesCollection.NewSeries
If Val(Application.Version) >= 12 Then
.ChartType = xlXYScatterSmoothNoMarkers
.Border.Weight = xlThin
End If
.XValues = "=" & Application.ConvertFormula( _
rng.Columns(1).Address(external:=True), xlA1, xlR1C1)
.Values = "=" & Application.ConvertFormula( _
rng.Columns(2).Address(external:=True), xlA1, xlR1C1)
End With
Next
Application.ScreenUpdating = True
End Sub
Function MakeSpiral(rdn As Double, rad As Double, pts As Long, _
xA As Double, yA As Double, _
xK As Double, yK As Double, _
arr() As Double)
Dim i As Long
For i = 1 To pts
arr(i, 1) = xA + (Cos(i * xK * rdn) * rad * i * 0.01)
arr(i, 2) = yA + (Sin(i * yK * rdn) * rad * i * 0.01)
Next
End Function
Jon - so what's up with the the 2007 chart macro recorder. How to do a
simple little thing like format the line weight (or rather points width).
Regards,
Peter T