Labeling points in an X-Y scatter graph?

D

Don Wiss

I'm using Excel 97. I'd like to label the points in an X-Y scatter graph. I
don't want to put the data values at the points, but a text label of my own
choosing. Is this possible?

Thanks, Don <donwiss at panix.com>.
 
G

Greg Wilson

Hi Don,

The simpliest way to do this to my reckoning is to
programmatically turn on the data labels and apply text to
them as in the example code below. Advised is that you
don't select the option to display the data labels but
instead rely on the code to do this. This way, you don't
need to have a data label for all points, only the ones of
your choosing.

The example code below uses a loop to individually turn on
and apply a month name to the first five points in the
selected series. The line ".HasDataLabel = True" turns on
the individual point and ".DataLabel.Text = Ar(i)" applies
the chosen text to the particular label (in this case an
element from an array).

Sub ChangeDataLabels()
Dim Ar As Variant, i As Integer
Ar = Array("Jan", "Feb", "Mar", "Apr", "May")
For i = 1 To 5
With ActiveSheet.ChartObjects(1).Chart. _
SeriesCollection(1).Points(i)
.HasDataLabel = True
.DataLabel.Text = Ar(i)
End With
Next
End Sub

Hope it's what you were looking for.

Regards,
Greg
 
G

Greg Wilson

Correction to my post:
I left out the declaration "Option Base 1" which should be
placed at the top of the module.

Regards,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top