Page 1 of 1

Setting XValue of TCursorTool

Posted: Sun Feb 13, 2005 6:48 pm
by 8441963
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

Posted: Mon Feb 14, 2005 10:04 am
by Marjan
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;

Posted: Mon Feb 14, 2005 1:59 pm
by 8441963
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)

Posted: Mon Feb 14, 2005 3:20 pm
by 9333098
Try Chart1.Update before your cursor positiong code.

Posted: Mon Feb 14, 2005 4:18 pm
by 8441963
Yeeeha! Thanks for the hint. Works absolutley perfect now