MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Naming individual data points on a graph

Posted by Conor Davies on October 30, 2001 9:13 AM

Easy problem..?

I have 3 columns of data; Name, Score1, Score2.
I plot an XY-scatter graph of Score1 vs. Score2.
When I point my cursor over an individual point I want a little label to appear that tells me the Name of the person to whom the point belongs.
Is this possible and easily achievable?

I have a 4th column, Class, can I have my data label show the Name AND the Class when I hold the cursor over an individual point?

Many thanks in advance.
Conor Davies

Posted by Damon Ostrander on October 30, 2001 3:43 PM

Hi Conor,

I don't know of a way to make the tip text (the label that appears when you put your cursor over an individual point) appear, but here is how you can make all the labels appear at once. This assumes the data start in row 1 (no headers), and includes column D:

Sub AddLabels()

With ActiveSheet.ChartObjects(1).Chart
ActiveWindow.Visible = False
For i = 1 To .SeriesCollection(1).Points.Count
With .SeriesCollection(1).Points(i)
.HasDataLabel = True
.DataLabel.Text = Cells(i, 1) & vbCr & Cells(i, 4)
End With
Next i
End With

End Sub

This of course assumes that the chart of interest is the first chart on the active worksheet. If you want to get rid of the labels, simply select the chart, go to Excel menu Chart -> Chart Options -> Data Labels, select the None option. Once you click OK this will permanently remove the labels, so you will have to rerun the macro to put them back on.

I hope this helps.