+ Reply to Thread
Results 1 to 2 of 2

Legend to follow scatter plot colors

  1. #1
    Registered User
    Join Date
    08-24-2011
    Location
    Malmo
    MS-Off Ver
    Excel 2010
    Posts
    1

    Legend to follow scatter plot colors

    Hi!

    I have a problem where I'm trying to change the color of my different points in my scatter plot depending on a third column. Managed to get the colors right, but have no idea how to get the legend to display the different color (and if possible the content of a fourth colomn). data can look like this

    0.2 0.3 1 A
    0.6 0.8 1 A
    0.2 0.5 3 C
    0.6 0.1 2 B
    0.8 0.9 1 A
    0.1 0.7 4 D
    ...

    Code for solving the plot color problem looks like follows

    Sub colorXY()

    Dim rngData As Range
    Dim lngIndex As Long
    Dim lngColor As Long

    Set rngData = Worksheets("cheat1").Range("C2:C10")
    With ActiveChart
    With .SeriesCollection(1)
    For lngIndex = 1 To .Points.Count
    Select Case rngData.Cells(lngIndex, 1).Value
    Case Is > 3
    lngColor = RGB(0, 0, 255)
    Case Is > 2
    lngColor = RGB(0, 255, 0)
    Case Is > 1
    lngColor = RGB(255, 0, 0)
    Case Else
    lngColor = RGB(255, 255, 255)
    End Select
    With .Points(lngIndex).Format.Fill
    .ForeColor.RGB = lngColor
    .BackColor.RGB = lngColor
    End With
    Next
    End With
    End With
    End Sub

    In the above example I would like to have four entries to the legend. One for each color(column 3 (C)) and name (column 4).
    Last edited by skorpan; 08-24-2011 at 08:14 AM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Legend to follow scatter plot colors

    It has been my experience that the entries are pretty much tied directly to the plotted series. While it is possible to delete a legend entry without deleting the plotted series, it seems impossible to add a legend entry that doesn't point to a specific series plotted in the chart. With that in mind, I would expect that the first step in finding a solution to your situation would be to somehow get all the 1's together, all the 2's together, and so on. That can be done either by sorting the list on columns 3 or 4, or you can use filters or worksheet functions to copy each set to another section/tab of the spreadsheet. Then you can plot each range as it's own series and you will get a legend entry for each series.

    If you don't like that, you might consider just adding a text box in which you can put whatever text you need to describe the points, but it won't be tied to the series names and formats like the legend box.

+ 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