+ Reply to Thread
Results 1 to 12 of 12

Color code data points on a scatter chart (2007)

  1. #1
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Color code data points on a scatter chart (2007)

    Hi Everyone,

    Does anyone know if there's a way to color code points on a scatter chart based on their values in a "3rd dimension" (i.e. other than the 2 dimensions represented by the chart axes).

    You might imagine a scatter chart that plots transactions by price (y) and units purchased (x).

    In that scenario, it might also be nice to color code each point by the region that made the sale.

    The only way I know to do this is to manually create separate columns of data for each region, so that each region can be plotted on the scatter chart as a separate data series.

    But since I'd like to experiment with several color coding alternatives, I'm wondering if there isn't a simpler way...

    For instance, Rob Bovey's "XY Chart Labeler" can add data point labels to a scatter chart...

    Is there, perhaps, another add-in that might enable color coding of data points based on a 3rd set of values?

    Just wonderin'...

    Cheers,

    Jay
    Last edited by JayUSA; 06-22-2009 at 08:56 PM.

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

    Re: Color code data points on a scatter chart (2007)

    In can use code to set the colour of each point based on a set of value bands.

    Please Login or Register  to view this content.
    In this case C2:C6 contains a value between 0 and 10 that has 1 of 3 colours assigned.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Re: Color code data points on a scatter chart (2007)

    Andy!

    Again, thank you very much for your thoughtful and detailed response to my question!

    I have downloaded your spreadsheet, and I am keen to use it as a model.

    However, I find that when I change the values in "3rd Value" column, the colors of the scatter points don't change.

    In other words, the color of the scatter points may have initially correlated with the values of "3rd Value", but they don't stay synced.

    Do I need to explicitly run or refresh the VBA script somehow? I'm afraid, I'm not VBA literate so I really don't know.

    Cheers,

    Jay

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

    Re: Color code data points on a scatter chart (2007)

    Yes you will need to run the macro again in order for it to colour based on the new data.

    ALT+F8 will display the macro dialog, where you can select the macro and run it.

    You can assign the macro to a shape or button to make it easier to refresh.

  5. #5
    Registered User
    Join Date
    06-01-2009
    Location
    India
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    66

    Lightbulb Re: Color code data points on a scatter chart (2007)

    Quote Originally Posted by JayUSA View Post
    Andy!


    However, I find that when I change the values in "3rd Value" column, the colors of the scatter points don't change.

    Cheers,

    Jay
    You can use it as a sub with worksheet change event. That will run this module whenever data on the worksheet changes. But note that when anything (means ANYTHING) changes on the worksheet, this module will execute.

    Or a better way is to change this macro to change only when a particular range is updated, and this range would be the cells where your data lies (I have not seen the attached excel so could not specify which columns and which rows)
    Mohit Khurana, CFA

    Excel Matic - A blog on MS Excel

    List of Essential Excel Shortcuts

    e-Book on Excel Math Functions

    Please add to our reputation if you find our replies as helpful.

  6. #6
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Re: Color code data points on a scatter chart (2007)

    Great Guys!

    Now I get it! Very helpful & problem solved!

    Thanks again, very much!

    Jay

  7. #7
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Re: Color code data points on a scatter chart (2007)

    First of all.... a big THANK YOU to Andy and Mohit.

    Second... I thought I was all set-to-go, but then I ran into lots of problems actually trying to apply this VBA code to my worksheet. The problems started as soon as converted the chart from an object to a sheet. Then I got even more confused...

    So.. I am now attaching a very, very simple and very clean micro-version of my spreadsheet.

    If one of you, or someone else, could get the scatter plots to receive a color according to their source ("source1", "source2",etc...), I would indeed be very, very grateful.

    Since I have next to zero VBA skills, I think it will be much more instructive for me to see how this code is applied to my specific situation, than to try to blindly apply it myself.

    Again, I could not be more grateful!

    Cheers,

    Jay
    Attached Files Attached Files

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

    Re: Color code data points on a scatter chart (2007)

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    04-26-2009
    Location
    Austin, TX
    MS-Off Ver
    Excel 2016
    Posts
    241

    Re: Color code data points on a scatter chart (2007)

    Hi Andy,

    I am so grateful and impressed by your assistance that I just had to find and read your bio to learn who you are!

    And then I had to go look-up the word "bespoke" -- as in "bespoke solutions"!

    Anyway, as you can probably tell, I'm astonished by the degree of interest and assistance that continuously flows from you, Martin, DonkeyOte and the other forum heavy-hitters.

    Anyway... back to business...

    I was very successful in my effort to import the "bespoke" VBA code you kindly supplied, and it is up and running well in my spreadsheet -- beautiful!

    Well, beautiful with a hitch -- the hitch is that my data table contains hundreds of rows of data, and I use Autofilters to identify the data I wish to plot at any time on my scatter chart.

    Unfortunately, the code that you customized for me does not work properly with respect to plotting a subset of data using Autofilters. And I don't understand enough about the code's internal logic to hypothesize about the specific nature of the problem.

    I really feel like you have already provided far more assistance than I could reasonably hope to receive -- but I am just wondering if there is an easy modification that will allow your code to live happily in my environment.

    Lastly, though I'm sure you understand the issue I describe, you can see it in vivo by taking a peek at my updated sample spreadsheet. It's all very self-explanatory.

    In any event, thanks again for your extra-ordinary help with this issue.

    Cheers,

    Jay
    Attached Files Attached Files

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

    Re: Color code data points on a scatter chart (2007)

    The code requires a tweak in order to handle filtered range.

    This change moves through the Areas and Cells of the visible range.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-25-2012
    Location
    Arkansas, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Color code data points on a scatter chart (2007)

    Hi Andy,

    Your code has helped me greatly. Thanks so much.
    I got my scatter chart all color coded. Now I need to make a legend to show the meaning of each color. Do you have a code that make this legend?

    Thanks So much.

    Quote Originally Posted by Andy Pope View Post
    Please Login or Register  to view this content.

  12. #12
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Color code data points on a scatter chart (2007)

    Bernadine,
    Welcome to the Forum, unfortunately:

    1. Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

    2. Please do not quote whole posts.
    Ben Van Johnson

+ 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