Page 1 of 1

Adding time/event marker to XY graphs

Posted: Tue Apr 11, 2006 8:27 pm
by 9231987
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

Posted: Wed Apr 12, 2006 7:52 am
by narcis
Hi MTW,

Yes, you can use TAnnotationTool for that. You'll find several examples at TeeChart's feature demo, available at its program group.

Posted: Wed Apr 12, 2006 5:02 pm
by 9231987
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.

Posted: Thu Apr 13, 2006 7:46 am
by narcis
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;