LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Positioning datalabels

If for example I want to place a particular label exactly over a point,

I know that's not your real question but if that was, simply
ActiveChart.SeriesCollection(1).DataLabels.Positio n = xlLabelPositionCenter

But if I follow, your real question is how to get the XY coordinates of your
XY points. Have a go with the following

Create an XY embedded chart with one series, keep it simple let each X:Y
make a straight line starting with X:Y = 0:0, 1:1 etc

Option Explicit
Sub test()
Dim i As Long
Dim cht As Chart
Dim sr As Series
Dim aX As Axis, aY As Axis
Dim x0 As Single, y0 As Single, xP As Single, yP As Single
Dim xf As Double, yf As Double
Dim arrX, arrY

Set cht = ActiveSheet.ChartObjects(1).Chart
Set aX = cht.Axes(1)
Set aY = cht.Axes(2)

x0 = aY.Left + aY.Width
y0 = aX.Top + aX.Height

yf = y0 - aY.Top
xf = (aX.Left + aX.Width - x0)

xf = (aX.Left + aX.Width - x0) / (aX.MaximumScale)
yf = (y0 - aY.Top) / aY.MaximumScale

Set sr = cht.SeriesCollection(1)
With sr
arrX = .XValues
arrY = .Values
For i = 1 To .Points.Count
xP = x0 + arrX(i) * xf
yP = y0 - arrY(i) * yf
With .DataLabels(i)
.Left = xP
.Top = yP
End With
Next
End With

End Sub

I know yesterday you said you are working with an MS Graph, I think it
should work pretty much the same way but try the above in Excel. First with
a straight line, then your "difficult" data.

The idea is to create your own co-ord system centred in the intersection of
the XY axes, then scale X & Y according to the length to right and above the
intersection. Where a chart does not have either of those axes would use
the plot-area instead.

I'll leave the hard part to you, as to how to work out quite where to place
those labels on a crowded chart. Actually I'd be interested to see!

Almost forgot to say, for some reason data labels don't seem to expose there
width & height properties, hence in this demo top-left label corners are
placed over points (if it works as intended). I imagine you'll be able to
guesstimate sizes depending on text & font, otherwise there's a much more
long winded way to get a good idea of the size.

Regards,
Peter T



"Phil Stanton" wrote in message
et...
I have a scatter chart and I want to be able to position the labels
differently for each point ( depending on the space available on the

chart)

I know the X & Y co-ordinates of the points in the series.

The chart is 622 point wide and the interior width of the plot area is 422
point wide. I know the height and width of the label

If for example I want to place a particular label exactly over a point,

what
is the calculation using the X co-ordinate, widths to give me the
DataLabel.Left value

Thanks for any help

Phil




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataLabels FGM Excel Programming 1 May 11th 07 03:20 PM
2007: .DataLabels.Position MrT Excel Programming 1 November 28th 06 01:44 AM
Overlapping DataLabels [email protected] Excel Programming 0 August 29th 06 01:42 PM
Excel Chart Datalabels Sean Howard Excel Programming 6 April 20th 04 12:04 AM
Datalabels on Scatter Daniel Bonallack[_2_] Excel Programming 1 September 15th 03 10:23 PM


All times are GMT +1. The time now is 07:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"