+ Reply to Thread
Results 1 to 8 of 8

Add multiple series to chart and plot by columns

  1. #1
    Registered User
    Join Date
    04-05-2017
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    57

    Add multiple series to chart and plot by columns

    Hi,

    I'm new to plotting using VBAs and I'm having an issue adding multiple series to an existing chart. I think the main problem is that the data in my worksheets is in kind of a unique orientation that, due to the way that it's collected and amended, has to remain that way.

    data example.JPG

    Using SetSourceData I can get the first data set to plot with x-axis values in J49 and J50 and y-axis values in K49 and K50. I would like to add the other sets as well which I assume would need some type of a For loop since the number may change. I've also been looking at series collections but can't get that to work either.

    This is what I have. It's mostly fluff at the moment.

    With newCht
    .ChartType = xlXYScatterLines
    .SetSourceData Source:=ActiveSheet.Range("J49:K50"), PlotBy:=xlColumns
    .HasTitle = True
    .ChartTitle.Text = chartName
    .Legend.Position = xlRight
    With .Parent
    .Name = chartName
    End With
    End With

    Thanks in advance.

  2. #2
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Add multiple series to chart and plot by columns

    Hi
    try this macro

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-05-2017
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    57

    Re: Add multiple series to chart and plot by columns

    Awesome! This worked great. Thanks for the help.

  4. #4
    Registered User
    Join Date
    04-05-2017
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    57

    Re: Add multiple series to chart and plot by columns

    I wanted to resurrect this kind of. So I've gotten the chart to plot and also added an additional line to name each trend using the value of a specific cell. It looks something like this:

    Please Login or Register  to view this content.
    One thing that I noticed though is that, unlike the Values and XValues, the Name value doesn't update in either the formula bar on in the chart legend without running the macro again. The cell also isn't highlighted like the ones for the values are. Is there a way to get them to update automatically?

  5. #5
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Add multiple series to chart and plot by columns

    Hi
    try this variation. it assumes your series names are in column A starting at row 49. Because the series are plotted by columns and each series has 2 data points it assumes the names are in every other row i.e. 49, 51 etc.

    Please Login or Register  to view this content.
    Last edited by NickyC; 04-17-2017 at 09:42 PM. Reason: typo

  6. #6
    Registered User
    Join Date
    04-05-2017
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    57

    Re: Add multiple series to chart and plot by columns

    I'm still having the same issue. Here's my code as it currently stands:

    Please Login or Register  to view this content.
    To illustrate what the issue is, if I click on the first trend as shown in the image below: the formula bar correctly shows the name as "Thing 1" and the cells where the data originates are highlighted.

    plot1.JPG

    However if I change the name to "Thingzzz" and the value in C3 to 50 then trend name in the formula bar doesn't change but the line itself does.

    plot2.JPG
    Attached Files Attached Files
    Last edited by pp57; 04-25-2017 at 07:24 PM. Reason: Added sample file.

  7. #7
    Forum Expert
    Join Date
    06-09-2010
    Location
    Australia
    MS-Off Ver
    Excel 2013
    Posts
    1,714

    Re: Add multiple series to chart and plot by columns

    Hi
    I think your problem is that you are still using

    Please Login or Register  to view this content.
    to set the series name. This adds the name as a string to the formula, rather than creating a link to the source cell. To have a dynamic link that changes when the source cell changes, you need to enter the name as a formula, which is what this piece of my revised code should do:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-05-2017
    Location
    Houston, TX
    MS-Off Ver
    2016
    Posts
    57

    Re: Add multiple series to chart and plot by columns

    Stepped away from this for a while but with NickyC's latest comments it's working how I need it to. I have some other things that I want to add to the chart now but I'll make a new thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 07-19-2015, 03:22 PM
  2. Scatter plot - plotting multiple series using only two columns
    By PPaviaSCOG in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 02-02-2015, 01:24 PM
  3. Scatter Plot Chart with multiple series
    By hyattj in forum Excel General
    Replies: 0
    Last Post: 08-14-2014, 03:36 PM
  4. Replies: 2
    Last Post: 03-05-2013, 03:07 PM
  5. Plot multiple series of events on a timeline chart
    By thehumble1 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 11-18-2009, 06:13 PM
  6. Expand Chart Macro to Plot Multiple Series
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-19-2006, 10:05 AM
  7. [SOLVED] chart data series -- plot a table as a single series
    By hjc in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 09-20-2005, 01:05 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