Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default xy scatter chart, macro to fill shapes

Hi,

I am working on a macro in excel that will take several series and plot them
on a scatter chart. Then the series will be made into a shape and filled in
with a certain color.

The problem I am having now is that when I try to make a small rectangle
(For instance the coordinates: (0,0) (0,0.2) (1,0.2) (1,0)) the shape builder
skips the third point and ends up making a triangle. This problem goes away
once the plot area is made larger, or the points aren't as close together.
The four points are plotted in the correct locations, but the shape builder
is not doing something right.

Here is the piece of code that I believe is giving me trouble;

Xnode = Xleft + (mySrs.XValues(Ipts) - Xmin) * Xwidth / (Xmax - Xmin)
Ynode = Ytop + (Ymax - mySrs.Values(Ipts)) * Yheight / (Ymax - Ymin)
myBuilder.AddNodes msoSegmentLine, msoEditingAuto, Xnode, Ynode

Thank you for your help,
Cameron
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default xy scatter chart, macro to fill shapes

Drawing very small shapes in any Office program can be hazardous to your
health! Office rounds coordinates of shapes to the nearest 0.75 point or
pixel or something like that. If your coordinates are near the rounding
limit, you will see cases where two very close points end up in the same spot.

One way to overcome this is to build a bigger shape, copy it to the
clipboard, and then paste it back in as "Enhanced Metafile". Then you can
scale it down as small as you want and it will retain its shape. Something
like this:

'
' Draw the shape
'
With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, 185.25, 121.5)
.AddNodes msoSegmentLine, msoEditingAuto, 272.25, 121.5
.AddNodes msoSegmentLine, msoEditingAuto, 272.25, 201#
.AddNodes msoSegmentLine, msoEditingAuto, 186.75, 201#
.AddNodes msoSegmentLine, msoEditingAuto, 185.25, 121.5
.ConvertToShape.Select
End With
'
' Send the shape to the clipboard
'
Selection.Cut
'
' Paste back in and then scale and translate as desired
'
ActiveSheet.PasteSpecial Format:="Picture (Enhanced Metafile)",
Link:=False _
, DisplayAsIcon:=False
Selection.ShapeRange.ScaleWidth 0.2, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.2, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.IncrementLeft 110.25
Selection.ShapeRange.IncrementTop 108#

HTH,

Eric

"Cameron" wrote:

Hi,

I am working on a macro in excel that will take several series and plot them
on a scatter chart. Then the series will be made into a shape and filled in
with a certain color.

The problem I am having now is that when I try to make a small rectangle
(For instance the coordinates: (0,0) (0,0.2) (1,0.2) (1,0)) the shape builder
skips the third point and ends up making a triangle. This problem goes away
once the plot area is made larger, or the points aren't as close together.
The four points are plotted in the correct locations, but the shape builder
is not doing something right.

Here is the piece of code that I believe is giving me trouble;

Xnode = Xleft + (mySrs.XValues(Ipts) - Xmin) * Xwidth / (Xmax - Xmin)
Ynode = Ytop + (Ymax - mySrs.Values(Ipts)) * Yheight / (Ymax - Ymin)
myBuilder.AddNodes msoSegmentLine, msoEditingAuto, Xnode, Ynode

Thank you for your help,
Cameron

Reply
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
How do you color fill flow shapes in your flowchart Cindi Gordon Excel Discussion (Misc queries) 1 February 9th 09 07:29 PM
Shapes Fill mhisma Excel Programming 2 September 26th 08 01:21 AM
Macro to add labels to data points in an xy scatter chart Scott Wagner Charts and Charting in Excel 2 December 17th 05 01:46 AM
Adding shapes to xy scatter charts Richw Excel Programming 2 October 14th 05 04:15 PM
Fill.backcolor and forecolor do not consistent in Chart and Shapes Cool Sport Excel Programming 1 September 26th 05 05:52 AM


All times are GMT +1. The time now is 09:37 PM.

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

About Us

"It's about Microsoft Excel"