TAnnotationTool Update Problem

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
maxc1972
Newbie
Newbie
Posts: 1
Joined: Thu May 03, 2012 12:00 am

TAnnotationTool Update Problem

Post by maxc1972 » Mon Dec 10, 2012 12:55 pm

hi, I have a chart with some TannotationTools on it. When i draw the chart the first time the annotations are in the correct position, when i zoom the chart the annotation are "one step back". I use the chart onafterdraw event to update the annotation position.
In the attached image you can see an example of that i obtain.

Another problem is that in the onafterdraw event i set the label for the annotation but i don't have access (the size is 1) to the size of the annotation next in the event.

i.e.:
procedure TFMain.DBChart1AfterDraw(Sender: TObject);
begin
AnnotationTool.Text := 'Some text';
AnnotationTool.Visible := True;
// here AnnotationTool.Width is 1
[...]
end;

Any idea to solve the problem?
Attachments
charts.jpg
charts.jpg (111.93 KiB) Viewed 2969 times

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TAnnotationTool Update Problem

Post by Yeray » Mon Dec 10, 2012 3:28 pm

Hi,

Note the OnAfterDraw event is executed once the chart has been drawn, so changing the position of any if the elements won't take effect until the next repaint.
You can change the position of the element on that event, and force a chart repaint, but this has the risk to create an endless loop.
In the following example, I only repaint the chart if the position of the Annotation is being altered.

Code: Select all

uses Series, TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;

  Chart1.AddSeries(TAreaSeries).FillSampleValues;
  Chart1.Tools.Add(TAnnotationTool);
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var XPos, YPos: Integer;
begin
  with Chart1[0] do
  begin
    XPos:=CalcXPos(0) + (CalcXPos(Count-1)-CalcXPos(0)) div 2;
    YPos:=CalcYPosValue(YValues.MaxValue) + (CalcYPosValue(YValues.MinValue)-CalcYPosValue(YValues.MaxValue)) div 2;
  end;

  with Chart1.Tools[0] as TAnnotationTool do
  begin
    Chart1.Canvas.AssignFont(Shape.Font);
    Text:='Label in the Middle';
    XPos:=XPos-(Shape.Width div 2);
    YPos:=YPos-(Shape.Height div 2);
    if (Left<>XPos) or (Top<>YPos) then
    begin
      Left:=XPos;
      Top:=YPos;
      Chart1.Draw;
    end;
  end;
end;
I'm also using the TAnnotationTool Shape.Width and Shape.Height properties, and both seem to have correct values.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply