Page 1 of 1

Annotation Width

Posted: Thu May 27, 2004 6:07 pm
by 9336214
Old problem, new priority :-)

I am trying to position annotations in the middle of a series. I can get the middle of the series correctly:

lLeft := aSeries.CalcXPos(lLeft);
lRight := aSeries.CalcXPos(lRight);
lSeriesMiddle := lLeft + ((lRight-lLeft) div 2);

but when I try to get the annotation width:


lAnnWidth := aAnnTool.Shape.ShapeBounds.Right - aAnnTool.Shape.ShapeBounds.Left;

I always get the right value to be zero--the Right and Bottom parts of the TRect are both zero.

I am using the TChart.OnBeforeDrawSeries event to set their position. Is there a different event I should be using?

Thanks
Ed Dressel

Posted: Tue Jun 01, 2004 6:40 am
by Marjan
Hi, Ed.

The "problem" is if annotion tool width/height is set automatically (by calculating the space needed to accomodate text) the ShapeBounds rect is always set to (0,0,0,0). To get the auto-sized annotation toll width/height, you can use the following code:

Code: Select all

type TAnnotationAccess = class(TAnnotationTool);

procedure TForm1.Button1Click(Sender: TObject);
var R: TRect;
    w: Integer;
    dummynum,dummyx,dummyy: Integer;
begin
  R := TAnnotationAccess(ChartTool1).GetBounds(dummynum,dummyx,dummyy);
  ShowMessage('Width = '+IntToStr(R.Right-R.Left));
end;