Find coordinates of last value

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Marius
Newbie
Newbie
Posts: 28
Joined: Tue Jul 29, 2008 12:00 am

Find coordinates of last value

Post by Marius » Thu May 27, 2010 8:50 am

Hi

I have an intraday chart where the X axis has the hours from 08:00 to 18:00. Throughout the day the chart updates as time goes by.

I would like to add an Annotation to the right of the last added value. How can I find the X and Y coordinates of the last values to be added to a chart?

E.g. at 13:04 I added the value 34,567 but from the resolution I have on the Y axis I can't see what the exact value is so I need to add an annotation (which is easy, but what is the position I need?)

Marius

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

Re: Find coordinates of last value

Post by Yeray » Thu May 27, 2010 3:04 pm

Hi Marius,

You need to use series' CalcXPos and CalcYPos functions. Here you have an example:

Code: Select all

uses Series, TeeTools;

var Line1: TLineSeries;
    Annotation1: TAnnotationTool;

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

  Line1:=Chart1.AddSeries(TLineSeries.Create(self)) as TLineSeries;
  Line1.Pointer.Visible:=true;
  Line1.XValues.DateTime:=true;

  Chart1.Legend.Visible:=false;

  Annotation1:=Chart1.Tools.Add(TAnnotationTool.create(self)) as TAnnotationTool;

  Chart1.MarginRight:=10;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Line1.AddXY(Now,random*100);
  Annotation1.Text:=FormatFloat('#.##0', Line1.YValue[Line1.Count-1]);
  Chart1.Draw;
  Annotation1.Left:=Line1.CalcXPos(Line1.Count-1);
  Annotation1.Top:=Line1.CalcYPos(Line1.Count-1);
end;
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