XY Scatter plot labelling

keelip01

New Member
Joined
Nov 21, 2002
Messages
9
I have 3 columns consisting of; a label (an area name), an X value and a Y value. There are 365 rows.

The X and Y values have been charted in an XY Scatter Plot.

If I click on an individual data point in the chart, a text box appears with a label like: Series 1, 29.5, 37.6.

Is it possible, using VBA if necessary, to be able to display the label in some way (the area name, from the first column) for the selected data point?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this:

Code:
' --------------------------------
' Class module named Class1
' --------------------------------

Public WithEvents Ch As Chart

Dim IDNum As Long
Dim a As Long
Dim b As Long

Private Sub Ch_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
    Dim Rng As Range
'   *** Range containing labels - change to suit ***
    Set Rng = Worksheets("Sheet1").Range("A2:A5")
    Ch.GetChartElement x, y, IDNum, a, b
    If IDNum = xlSeries Then
        With ActiveChart.SeriesCollection(a).Points(b)
            .HasDataLabel = True
            With .DataLabel
                .Text = Rng.Cells(b, 1).Value
                .Position = xlLabelPositionAbove
            End With
        End With
    End If
End Sub

Private Sub Ch_MouseUp(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
    Ch.GetChartElement x, y, IDNum, a, b
    If IDNum = xlSeries Then
        With ActiveChart.SeriesCollection(a).Points(b)
            .HasDataLabel = False
        End With
    End If
End Sub

' ---------------
' Sheet module
' ---------------

Dim MyChart As New Class1

Private Sub Worksheet_Activate()
'   *** Change ChartObjects index to suit ***
    Set MyChart.Ch = ActiveSheet.ChartObjects(1).Chart
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,947
Messages
6,175,563
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top