Results 1 to 7 of 7

Plotting multiple arrays on same graph

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Plotting multiple arrays on same graph

    I am a little confused about how I should plot arrays. I am often confused with Charts and Chart Objects. I would like to pass arrays into a function that plots the arrays. In the main code getPlots I would like to make each column an array and divide it by the first column/array (I also need the first column divided by itself). In the plotting function, I often have an invalid parameter error, but I think my confusion comes from whether I am dealing with charts or chart objects. It happens in the plotting function in the line that says with activechart...

    I should add that the timeArray represents the x-values.

    Private Sub getPlots_Click()
    
        Dim numberOfRows As Integer
        Dim rowRange As Range
        Dim i, m, seriesIndex As Integer
        Dim firstArray() As Variant
        Dim secondArray() As Variant
        Dim timeArray()    As Variant
        
        If ActiveSheet.ChartObjects.Count <> 0 Then
            ActiveSheet.ChartObjects.Delete
        End If
    
        i = 5 'column number
        seriesIndex = 1
        
        Set rowRange = Range(Cells(8, i), Cells(Rows.Count, i).End(xlUp))
        numberOfRows = rowRange.Rows.Count + 7
        firstArray = Range(Cells(9, i), Cells(numberOfRows, i)).Value
        timeArray = Range(Cells(9, 4), Cells(numberOfRows, 4)).Value
        
        If ActiveSheet.ChartObjects.Count = 0 Then
            ActiveSheet.Shapes.AddChart.Select
            ActiveChart.ChartType = xlXYScatterLines
         End If
        
        While Cells(8, i) <> ""
    
            Set rowRange = Range(Cells(8, i), Cells(Rows.Count, i).End(xlUp))
            numberOfRows = rowRange.Rows.Count + 7
            
    
            secondArray = Range(Cells(9, i), Cells(numberOfRows, i)).Value
    
            Call createPlot(firstArray, secondArray, timeArray, seriesIndex)
            i = i + 1
            seriesIndex = seriesIndex + 1
        Wend
    
    
    End Sub
    
    Function createPlot(firstArray As Variant, secondArray As Variant, timeArray As Variant, seriesIndex As Integer)
    
        Dim normalizedArray() As Variant
        Dim array1() As Variant
        Dim array2() As Variant
        Dim time() As Variant
        Dim yArray() As Double
        Dim m, i, size, index As Integer
            
        array1 = firstArray
        array2 = secondArray
        time = timeArray
        index = seriesIndex
        
        i = 0
        size = UBound(array1, 1)
        ReDim yArray(size)
        
        For m = LBound(array1, 1) To UBound(array1, 1)
            
            yArray(i) = array2(m, 1) / array1(m, 1)
            i = i + 1
            
        Next m
        
         If ActiveSheet.ChartObjects.Count <> 0 Then
             ActiveSheet.ChartObjects.Select
        End If
        
       With ActiveChart.SeriesCollection(index)
        .XValues = time
        .Value = yArray
           
       End With
    
        
        
    End Function
    Last edited by NatalieEC; 11-05-2014 at 02:17 PM. Reason: Found some solution to first question, asked to change title

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Array handling questions
    By James McMurray in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-22-2008, 11:19 PM
  2. array questions
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2005, 03:15 AM
  3. Array questions
    By Perico in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2005, 04:05 PM
  4. Array Functions - Two Questions
    By MDW in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-12-2005, 03:06 PM
  5. Making progress with array functions, another two questions
    By Don Taylor in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2005, 05:06 PM

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