Adding time/event marker to XY graphs

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
MTW
Newbie
Newbie
Posts: 18
Joined: Fri Apr 02, 2004 5:00 am

Adding time/event marker to XY graphs

Post by MTW » Tue Apr 11, 2006 8:27 pm

Is there a function to add time/event markers to an XY graph. For example, if a function is being plotted vs time and you want to indicate an external event occurred at a specific time (draw a line with a label at that time), is a function provided for this, or must it be done manually?

Thanks

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Apr 12, 2006 7:52 am

Hi MTW,

Yes, you can use TAnnotationTool for that. You'll find several examples at TeeChart's feature demo, available at its program group.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MTW
Newbie
Newbie
Posts: 18
Joined: Fri Apr 02, 2004 5:00 am

Post by MTW » Wed Apr 12, 2006 5:02 pm

Thank you for your assistance. However, if I look at the examples and understand correctly, the annotation is not actually linked to the chart. For example, if I wanted to indicated a time event at 1 second into the data, I could use TAnnotationTool, to place text in a box at that position, however, if the user scrolls the graph, the annotation stays in place and is not actually linked to the 1 second position on the X-Axis. Is this correct?

If so, the Annotation tool would be serve my requirements. I was looking for a function, to perhaps draw a verticle line on the chart at the position, with an ability to label the line.

Any other suggestions would greatly be appreciated.

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Thu Apr 13, 2006 7:46 am

Hi MTW,

To have the annotation or custom drawings updated when user zooms or scrolls the chart you can do something like the code below. In the snippet below it is shown how to place an annotation tool and how to custom draw on TeeChart's canvas.

Code: Select all

procedure TForm1.SetCallout(AIndex: Integer);
begin
  // Re-position annotation callout
  with ChartTool1.Callout do
  begin
    Visible:=True;
    XPosition:=Series1.CalcXPos(AIndex);
    YPosition:=Series1.CalcYPos(AIndex);
    ZPosition:=0;

    ChartTool1.Left:=XPosition-20;
    ChartTool1.Top:=YPosition-50;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues();
  Index:=5;

  // force a first-time chart redrawing, to obtain valid
  // coordinates (Series1.CalcYPos, etc).
  Chart1.Draw;

  // Start positioning annotation callout at point index 5
  SetCallout(Index);

  ChartTool1.Callout.Arrow.Visible:=True;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  SetCallout(Index);
  CustomDrawing(Index+5);
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  Chart1.Draw;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  Chart1.Draw;
end;

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
  Chart1.Draw;
end;

procedure TForm1.CustomDrawing(AIndex: Integer);
begin
  with Chart1.Canvas do
  begin
    MoveTo(Series1.CalcXPos(AIndex),Chart1.ChartRect.Top);
    LineTo(Series1.CalcXPos(AIndex),Chart1.ChartRect.Bottom);
    RotateLabel(Series1.CalcXPos(AIndex),Series1.CalcYPos(AIndex),'My Custom Text',90);
  end;
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply