X Labels for XY Scatterplot

mlauffer

New Member
Joined
May 22, 2017
Messages
1
Hello!

I have coordinate data (specific X and Y value) that I am trying to plot as a scatterplot.
What I am plotting is coordinates for a location for every trial in an experiment, so it would look like this:

TrialXY
1504340
2507338
3518335
4527333
5539331
6549328
7560321
8566319
9571316

<tbody>
</tbody>

I can plot my coordinates just fine, but the field that allows you to label x data points in the "select data" menu is inactive. How can I label each point to indicate it's trial number? Do I need to make each trial a separate series?

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
First, place the following code in a regular module (Visual Basic Editor > Insert > Module > Copy/Paste > Close and return to Microsoft Excel). Then, select/activate your XY Chart, and try running the macro...

Code:
[COLOR=darkblue]Sub[/COLOR] AddLabelsToXYChart()

    [COLOR=darkblue]Dim[/COLOR] rLabels [COLOR=darkblue]As[/COLOR] Range
    [COLOR=darkblue]Dim[/COLOR] sFormula [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] lPoints [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] i [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
    
    [COLOR=darkblue]If[/COLOR] ActiveChart [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
        MsgBox "Please select/activate an XY Chart, and try again.", vbExclamation
        [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
    [COLOR=darkblue]Select[/COLOR] [COLOR=darkblue]Case[/COLOR] ActiveChart.ChartType
        [COLOR=darkblue]Case[/COLOR] -4169, 74, 75, 72, 73
            [COLOR=green]'Do nothing[/COLOR]
        [COLOR=darkblue]Case[/COLOR] [COLOR=darkblue]Else[/COLOR]
            MsgBox "Please make sure the selected chart is an XY Chart, and try again.", vbExclamation
            [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Select[/COLOR]
    
    [COLOR=darkblue]With[/COLOR] ActiveChart
        sFormula = Split(.SeriesCollection(1).Formula, ",")(1)
        [COLOR=darkblue]Set[/COLOR] rLabels = Range(sFormula).Offset(, -1)
        .SeriesCollection(1).ApplyDataLabels Type:=xlDataLabelsShowValue, AutoText:=True, LegendKey:=[COLOR=darkblue]False[/COLOR]
        lPoints = .SeriesCollection(1).Points.Count
        [COLOR=darkblue]For[/COLOR] i = 1 [COLOR=darkblue]To[/COLOR] lPoints
            .SeriesCollection(1).Points(i).DataLabel.Text = rLabels(i, 1).Value
        [COLOR=darkblue]Next[/COLOR] i
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

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