Annotation and an Arrow

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Annotation and an Arrow

Post by TestAlways » Wed Apr 29, 2009 4:55 pm

I would like to add an annotation to a chart, which is pretty easy. But I need a few more features:

1) I need to add an arrow from the annotation to a specific location on the chart with the arrow connected to the closes point of the annotation; and

2) I would like to allow the user to move the annotation by dragging it to a new location.

Can items #1 and #2 be done?

Thank you,

Ed Dressel

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

Post by Yeray » Thu Apr 30, 2009 8:43 am

Hi Ed,

One solution could be allowing drag to your annotation, look at here. But I'm afraid that you should control your arrow position manually.

Another solution could be using a dummy point series with pointers hided and with DragMarks tool associated. This could be an example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var APosition: TSeriesMarkPosition;
    i: Integer;
begin
  Chart1.View3D := false;

  for i:=0 to 24 do
    Series1.Add(random*200);

  ChartTool1.Series := Series2;
  Series2.AddXY(10,100,'Your custom text');
  Series2.Marks.Visible := true;
  Chart1.Draw;

  Series2.Pointer.Visible := false;
  Series2.ShowInLegend := false;
  Series2.Marks.Arrow.Color := clRed;

  with Series2.Marks.Positions[0] do
  begin
    Custom := true;
    LeftTop.X := LeftTop.X+100;
    LeftTop.Y := LeftTop.Y-100;
    ArrowTo.X := ArrowTo.X+100;
    ArrowTo.Y := ArrowTo.Y-100;
  end;

  Chart1.Axes.Bottom.LabelStyle := talValue;
end;
If you don't like this, I'm afraid I can't think on anything easiest than drawing directly to the canvas.
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

TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Post by TestAlways » Thu Apr 30, 2009 2:25 pm

If you don't like this, I'm afraid I can't think on anything easiest than drawing directly to the canvas.
Thanks for the ideas. Is there an example of drawing my own arrow? e.g. what even should I used?

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

Post by Yeray » Thu Apr 30, 2009 3:21 pm

Hi Ed,

Here you have another possibility: The Rectangle Tool that is pretty similar than the Annotation but it allows dragging "out of the box".

Code: Select all

uses series, TeeTools;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AddSeries(TPointSeries.Create(self));
  Chart1[0].FillSampleValues(50);

  Chart1.Tools.Add(TRectangleTool.Create(self));

  with (Chart1.Tools[0] as TRectangleTool) do
  begin
    Text := 'My custom text';
    Left := 200;
    Top := 200;
    Callout.Arrow.Visible := true;
    Callout.Arrow.Color := clRed;
    Callout.XPosition := 100;
    Callout.YPosition := 100;
  end;
end;
If you still don't like it, I'll try to do a "custom drawing solution".
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