+ Reply to Thread
Results 1 to 21 of 21

Colour coding points on a scatter graph depending on a value in a cell

  1. #1
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Colour coding points on a scatter graph depending on a value in a cell

    Hello,

    I have created a scatter graph plotting the grades of students. There is a worksheet of student details including whether they are male of female, M and F. Is it possible to get the points on the scatter graph to appear red for girls and blue for boys based on the value that appears in these cells without manually doing it myself?

    Regards Stephen

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Can be done by macro. Suggest uploading a copy of the workbook so something can be coded.
    Martin

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

    Re: Colour coding points on a scatter graph depending on a value in a cell

    There is a worksheet of student details including whether they are male of female, M and F. Is it possible to get the points on the scatter graph to appear red for girls and blue for boys based on the value that appears in these cells without manually doing it myself?
    It is not something that Excel will do automatically. I always thought that the easiest way to do this was to separate the data into two data sets, one for M and one for F, then plot those as two different data series. By default, Excel will format each data series with different colors.

    If you decide that the data must be plotted as a single series, then it will require a macro as mrice suggests.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Hello,

    Unfortunately, I can not upload the actual spreadsheet I am working on as the contents is confidential. I have created another simplified version which I hope can help, however the actual version is in Excel 2003.

    Stephen
    Attached Files Attached Files

  5. #5
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Try this in a new module

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Hello,

    I am having trouble using this code, I have had a play around with it and it seems to work fine on its own but I am trying to use

    Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
    Application.ScreenUpdating = False

    Dim ElementID As Long
    Dim Arg1 As Long
    Dim Arg2 As Long


    Me.GetChartElement x, y, ElementID, Arg1, Arg2
    If ElementID = 3 Then
    ActiveChart.SeriesCollection(Arg1).Points(Arg2).ApplyDataLabels
    ActiveChart.SeriesCollection(Arg1).Points(Arg2).DataLabel.Font.Size = 12
    Z = 0
    For N = 5 To Sheets("Actual Grade").Cells(Sheets("Actual Grade").Rows.Count, 1).End(xlUp).Row
    If Sheets("Actual Grade").Cells(N, 1).Height > 0 Then
    Z = Z + 1
    If Z = Arg2 Then Exit For
    End If
    Next N
    ActiveChart.SeriesCollection(Arg1).Points(Arg2).DataLabel.Text = Sheets("Actual Grade").Cells(N, 1)
    Else
    On Error Resume Next
    ActiveChart.SeriesCollection(1).DataLabels.Delete
    On Error GoTo 0
    End If
    Application.ScreenUpdating = True

    End Sub

    As well as this code which is when it doesn't work, can the two codes work together to achieve the colour coding affect?

    Regards Stephen
    Last edited by steve145; 02-19-2013 at 12:48 PM.

  7. #7
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Not sure I understand what you are trying to do. The colour coding is a one off activity which you do the the chart when its created but the label appearance and disappearance is dynamic.

  8. #8
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    My spreadsheet involves lots of filtering of data (for which I am using the autofilter), this is then displayed in a scatter graph. The data points are from both males and females and so I would like the male points to be blue and the females red, but when I filter the data some of the males are red and females blue. Also how can I customise this code to fit my spreadsheet, as the genders F/M start on row 5 and are in column 7?

    Stephen

  9. #9
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Colour coding points on a scatter graph depending on a value in a cell

    This is getting a bit complex. Can you upload a real copy of the workbook (with substitute names) as it is difficult without something to test on.

  10. #10
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Hello,

    Here is the spreadsheet. The colour coding now does not work as you will see, an 'out of range' error message appears when I try to run the macro. I don't know if it is because I have not used the code correctly, can it be fixed?

    Regards Stephen
    Attached Files Attached Files

  11. #11
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Colour coding points on a scatter graph depending on a value in a cell

    The data range that your graphs are using is one row shorter than the data that the colour coding is working off. The code seems to work correctly if this is changed.

    (As a former school governing body Chair, the data looks very familiar )

  12. #12
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    The data range from my graphs will constantly change as I filter the data, can the code accommodate this and if so how?

    What sort of function did you have in your spreadsheet? Did you have the same sort of graphical output? If you don't mind me asking Hopefully this spreadsheet will prove useful when finished
    Last edited by steve145; 02-27-2013 at 02:57 PM.

  13. #13
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Suggest using this for colour coding

    Please Login or Register  to view this content.
    and these ranges for the graph

    ='Predicted Grade'!$N$5:$N$20

    ='Actual Grade'!$R$5:$R$20

  14. #14
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Works perfectly for those ranges and with that code, but when I filter the data it does not work. The points shows red and blue, but some of males and females. The user of this spreadsheet will constantly filter the data showing specific classes for comparison. Can the code accommodate the filtering changes to the data and still display if the student is male or female by colour of points?

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Colour coding points on a scatter graph depending on a value in a cell

    I agree with MrShorty-plotting two series is easier even though it takes a little time to set up
    Attached Files Attached Files
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  16. #16
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    I think this way would be better as it is easier to do as said by MrShorty. However looking at the revised spreadsheet, the female labels once hovered over are permanently visible, but I don't understand why. Can the two plotted series work with the hovering labels code so that the labels are only visible when being hovered over and disappear when not?

  17. #17
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Colour coding points on a scatter graph depending on a value in a cell

    change the Else part of the mouse move code from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    The females are still permanently visible. Would the whole code need to be changed as it is plotting two different series, meaning there are two different labels?
    Last edited by steve145; 02-28-2013 at 10:53 AM.

  19. #19
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Colour coding points on a scatter graph depending on a value in a cell

    no but you need to make sure you update the code in all your chart sheets

  20. #20
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Separating males and females into different series works perfectly but seems a bit tedious when changing the data being looked at in the graph. Can the original code accommodate the filtering?
    Last edited by steve145; 02-28-2013 at 12:03 PM.

  21. #21
    Registered User
    Join Date
    02-10-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003/ Excel 2007
    Posts
    21

    Re: Colour coding points on a scatter graph depending on a value in a cell

    Managed to solve the problem using the code if anyone else needs it it turns out the original code was still counting the hidden rows
    Please Login or Register  to view this content.

+ 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