chart manipulation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can i draw a rectangle on a chart
I have an x y scatter chart and want to draw a rectangle from known x y co
ordinates

thanks
 
This should put the upper left corner of the rectangle at the specified X
and Y values. You can adjust it to position the rectangle from there.

Sub AddRectangleToChart()
Dim yAxis As Axis, xAxis As Axis
Dim y1 As Single, x1 As Single
Dim x, y, shp As Shape
x = 2.19
y = 4.333
Set yAxis = ActiveChart.Axes(xlValue, xlPrimary)
Set xAxis = ActiveChart.Axes(xlCategory, xlPrimary)
y1 = yAxis.Top + yAxis.Height - ((y / (yAxis.MaximumScale -
yAxis.MinimumScale)) * _
yAxis.Height)
x1 = xAxis.Left + (x / (xAxis.MaximumScale - xAxis.MinimumScale)) * _
xAxis.Width

Set shp = ActiveChart.Shapes.AddShape( _
Type:=msoShapeRectangle, _
Left:=x1, _
Top:=y1, _
Width:=99.67, _
Height:=70.08)
shp.ZOrder msoBringToFrong
End Sub
 

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

Back
Top