+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    06-09-2009
    Location
    hk
    MS-Off Ver
    Excel 2003
    Posts
    4

    how to create a bar chart with data in an array

    i got data in two arrays in the macro, let say a() and b()
    and i want to get a bar chart of plotting a() as y-axis against b() as x-axis

    i got some codes like this if i post my data in the worksheet first, but i dont know how i can do it directly ... i dont want to show all my data in the worksheet...

    "Charts.Add
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(_ "K1:L10"), PlotBy:=xlColumns
    ....."

  2. #2
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2003, 2007
    Posts
    355

    Re: how to create a bar chart with data in an array

    Quote Originally Posted by eternity_forget View Post
    i got data in two arrays in the macro, let say a() and b()
    and i want to get a bar chart of plotting a() as y-axis against b() as x-axis

    i got some codes like this if i post my data in the worksheet first, but i dont know how i can do it directly ... i dont want to show all my data in the worksheet...

    "Charts.Add
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(_ "K1:L10"), PlotBy:=xlColumns
    ....."
    I think that we could never make a chart like that, because the range-source of a chart in Excel has to base on real cells in a worksheet.

    You may create a chart yourself by making a bar-chart with REPT(....) function
    .

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: how to create a bar chart with data in an array

    You can base you chart on array data but you will be restricted by the length of the Series formula. ~1024 characters

    You can hide the cells as long as you uncheck the option to 'Plot visible cells only'
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    06-09-2009
    Location
    hk
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: how to create a bar chart with data in an array

    Thanks both
    but could you please explain in detail ? 'cause i don't really understand ...

    @tigertiger - what is a REPT() function ? how to apply that ?

    @Andy Pope - can you tell me more about how to do that ?

    thanks in advance !!!

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: how to create a bar chart with data in an array

    Code:
        With Charts.Add
            With .SeriesCollection.NewSeries
                .Name = "Test"
                .Values = Array(1, 2, 3)
                .XValues = Array("A", "B", "C")
            End With
            .ChartType = xlColumnClustered
        End With
    Cheers
    Andy
    www.andypope.info

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