Results 1 to 3 of 3

Create chart using data array (not range)

Threaded View

  1. #1
    Registered User
    Join Date
    05-07-2009
    Location
    Chicago,US
    MS-Off Ver
    Excel 2003
    Posts
    1

    Create chart using data array (not range)

    Hey guys,
    I have the following sub and I want to create a chart by reading data from array. Because I don't want to have data in worksheets. However, the sub doesn't work if the array is too big (when n>55).
    Can somebody help me? I appreciate your help!

    But I don't think there is a way to solve this problem without 'printing' the numbers to the worksheet first.

    
    Public Sub CreateScatterPlot()
    Dim xValue() As Double, yValue() As Double
    Dim sx As String, sy As String, i As Integer
    Dim myChart As Chart, n As Integer
    
    Sheet1.Activate
    Sheet1.Cells(1, 1).Select
    Set myChart = Charts.Add
    With myChart
        .ChartType = xlXYScatter
        .Location xlLocationAsObject, Sheet1.Name
    End With
    
    With ActiveChart
        n = 50
        
        ReDim xValue(1 To n) As Double
        ReDim yValue(1 To n) As Double
        
        For i = 1 To n
            xValue(i) = i ^ 2 + 3
            yValue(i) = 2 * i + 1
        Next i
        
        sx = xValue(1)
        sy = yValue(1)
        For i = 2 To n
            sx = sx & "," & xValue(i)
            sy = sy & "," & yValue(i)
        Next i
    
        .SeriesCollection.NewSeries
        With .SeriesCollection(1)
            .Values = yValue
            .XValues = xValue
        End With
    
    End With
    End Sub
    Last edited by Pingu; 05-07-2009 at 11:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1