Setting XValue of TCursorTool

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Tooldesign
Newbie
Newbie
Posts: 5
Joined: Thu Nov 27, 2003 5:00 am

Setting XValue of TCursorTool

Post by Tooldesign » Sun Feb 13, 2005 6:48 pm

Hey

I have a TChart on my form and it displays 2 series and a third (hidden) one. Now I have a TCursorTool (snapping and vertical style only) which can be used to select a datapoint. I have datapoints every 15 seconds (timescaled axis). I save the selected point in a database (time-value).

But if I want to reload that chart (for editing), I have absolutley no idea how to set the CursorTool at the estimated point. I know, that for 04:15, it should be the 17th point of the chart. But if I set XValue to any value, it is at the end of my datapoints or at the beginning. I have tested putting out XValue when I move my CursorTool-line and I get very small values (0.00xxxx). I have absolutely no idea how this value is calculated.

Screenshot (like it should be after reloading)

Image

Thanks for any assistance

Edit: Using Delphi 7 with TeeChart Pro 6.01

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Mon Feb 14, 2005 10:04 am

Hi.

If you've setup the Snap property to true then only "good" values are exact point (x) values. If this is not the case (if you want to freely move cursor tool), set the Snap property to false and then manually control cursor tool poisition by using the following code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.XValues.DateTime := True;
  // x = 0:12:15
  Series1.AddXY(EncodeTime(0,12,15,0),5);
  // x = 3:05:00
  Series1.AddXY(EncodeTime(3,05,0,0),3);
  // x = 12:00:00
  Series1.AddXY(EncodeTime(12,0,0,0),6);
  // x = 17:03:05
  Series1.AddXY(EncodeTime(17,03,05,0),1);

  ChartTool1.Snap := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ChartTool1.XValue := EncodeTime(10,0,0,0);
end;
If this is not the case, you can use SnapToPoint method to reposition cursor tool to the nearest point:

Code: Select all

  ChartTool1.Snap := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ChartTool1.XValue := EncodeTime(3,0,0,0);
  ChartTool1.SnapToPoint;
end;
Marjan Slatinek,
http://www.steema.com

Tooldesign
Newbie
Newbie
Posts: 5
Joined: Thu Nov 27, 2003 5:00 am

Post by Tooldesign » Mon Feb 14, 2005 1:59 pm

Thanks lot for the hint with EncodeTime. This does correct placement over the chart. But there's one problem left. I can't set the XValue when the form is visible (OnCreate, OnShow). I have a workaround with a timer setting me the XValue after OnShow, but this isn't a pretty solution. Do you have any ideas? (although it's working now)

SteveP
Advanced
Posts: 132
Joined: Sun Sep 07, 2003 4:00 am

Post by SteveP » Mon Feb 14, 2005 3:20 pm

Try Chart1.Update before your cursor positiong code.

Tooldesign
Newbie
Newbie
Posts: 5
Joined: Thu Nov 27, 2003 5:00 am

Post by Tooldesign » Mon Feb 14, 2005 4:18 pm

Yeeeha! Thanks for the hint. Works absolutley perfect now

Post Reply