+ Reply to Thread
Results 1 to 3 of 3

Create chart using data array (not range)

Hybrid 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.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Create chart using data array (not range)

    Welcome to the forum, Pingu.

    Please take a few minutes too read the forum rules, and then edit both of your posts to add code tags.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Create chart using data array (not range)

    As you have discovered the SERIES formula has a finite length limit.

    See this page on ways to reduce the length of the array of values.
    http://peltiertech.com/Excel/ChartsH...ChartData.html

    You will save yourself a lot of heartache if you just use a worksheet to store the values. Hide the worksheet if you don't want the user to see it.
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

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