Recent

Author Topic: Tracking TChart cursor  (Read 1708 times)

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 567
Tracking TChart cursor
« on: September 20, 2023, 06:07:58 pm »
A minimal example of how to track mouse cursor location on a TChart.
« Last Edit: September 20, 2023, 06:50:06 pm by Curt Carpenter »

wp

  • Hero Member
  • *****
  • Posts: 12476
Re: Tracking TChart cursor
« Reply #1 on: September 20, 2023, 07:34:33 pm »
Yes, this works.

An idea for an extension: When you use a TDataPointCrossHairTool rather than a TUserDefinedTool you can utilize the fact that the mouse is caught near the data points and you can read out the exact values of the data points:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ChartToolset1DataPointCrosshairTool1Draw(
  2.   ASender: TDataPointDrawTool);
  3. var
  4.   ser: TChartSeries;
  5.   idx: Integer;
  6. begin
  7.   if ASender <> nil then
  8.   begin
  9.     if ASender.Series <> nil then
  10.     begin
  11.       ser := ASender.Series as TChartSeries;
  12.       idx := ASender.PointIndex;
  13.       Label3.Caption := 'Series "' + ser.Title + '": x = ' + ser.XValue[idx].ToString + ' y = ' + ser.YValue[idx].ToString;
  14.       exit;
  15.     end;
  16.     Label3.Caption := '';
  17.   end;
  18. end;

 

TinyPortal © 2005-2018