09-10-2010 03:38 PM
I would like to annotate a few peaks on a waveform graph, but I also want to achieve a certain balanced placement of the annotations. If I use the default alignment, alignment appears random and some annotations end up on top of one another at worst, on top of the plot line, or unbalanced at best. If I manually align them all with the same fixed values, the overall look is too rigid.
My goal is to have a balanced layout that uses the empty area above the plot line (or beside it, in the case of the highest peak, which doesn't leave room at the top of the graph for an annotation). Any ideas for how to achieve this goal?
09-10-2010 04:55 PM
Related: is an accurate way to get the bounds of an annotation so I can make computations and move them around myself? If I call GetBounds on an XYPointAnnotation, it seems to return the bounds of the whole graph (using NIMS 2009).
09-13-2010 12:23 PM
Hello Shawn,
You can use the CaptionAlignment method and the CaptionZOrder methods to set the positions for the annotations. If you want to get the size of the annotation box you can use:
Size rect = xyPointAnnotation1.ShapeSize;
Is this what you are looking to get? Or are you looking to get the size of the whole annotation including the arrow and caption?
Best Regards,
Adam G
09-13-2010 01:04 PM
Sorry, I was unclear there. What I'm looking for bounds-wise is the caption bounds. The shape will always be on a point on the plot line, but I want to balance the captions in open space. To do think I think I need the caption bounds relative to the plot area.
09-14-2010 04:45 PM
Hello Shawn,
Unfortunately there is not a method to get the caption bounds. A possible workaround would be to use a monospace font for the caption then get the string length and this way you would know how many pixels are being used and you should then be able to place it accordingling. Have a great day!
Best Regards,
Adam G
09-15-2010 12:37 AM
Hi there,
Use the Graphics.MeasureString() method to get the size of caption.
And use the XYAnnotation.SetCaptionPosition() method to set the position of the caption.
Using these two you can calculate the bounds of the caption.
Regards,
Vijet Patankar
National Instruments
09-15-2010 07:51 AM
Thanks, Adam and Vijet. I'm not sure if SetCaptionAlignment overrides CaptionAlignment or how the two properties interact, but this sounds like it could work.