[SOLVED] value of hinttool.NearestGraphPoint.y is not exactly the original value lazarus / 55-TAChart ---------------------------------------------------------------------- kinlion · 2018-12-07 05:40 I add some LineSeries to a Chart, and show hint when mouse on a data point. Similar to wp said in the post https://forum.lazarus.freepascal.org/index.php/topic,34723.0.html I write: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmLTPlanManager.ChartToolset1DataPointHintTool1Hint(  ATool: TDataPointHintTool; const APoint: TPoint; var AHint: String);var  hinttool: TDataPointHintTool;  ser: TLineSeries;begin  hinttool := TDataPointHintTool(ATool);  ser := TLineSeries(hinttool.Series);     // this is the clicked series  if ser = nil then    exit;   AHint := Format('%6d日 %s %.0n支',      [        trunc(hinttool.NearestGraphPoint.X),        ser.Title,        hinttool.NearestGraphPoint.y      ]);end;  However, the hint value from hinttool.NearestGraphPoint.y is not the original value. Why? ---------------------------------------------------------------------- wp · 2018-12-07 09:34 Oh, I was not aware of this. It is because the "NearestGraphPoint" is calculated back from the screen pixels of the data point which leads to some inaccuracies. I don't know why it is made like this, probably because the corresponding TDataPointTool method is very general and must work also for series which do not require discrete listed data (such as TFuncSeries). A better way is to directly read the x,y values from the series or the chart source. If your data are stored in the internal listsource of the lineseries you can simply call ser.XValue[index] and ser.YValue[index] where index is the series point index returned by ther chart tool (ser.PointIndex): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ChartToolset1DataPointHintTool1Hint(ATool: TDataPointHintTool;  const APoint: TPoint; var AHint: String);var  ser: TLineSeries;  index: Integer;begin  if (ATool = nil) or (ATool.Series = nil) then  AHint := ''  else begin    ser := TLineSeries(ATool.Series);    index := ATool.PointIndex;    AHint := Format('Series "%s":' + LineEnding + '  x = %.3f' + LineEnding + '  y = %.3f',      [ser.Title, ser.XValue[index], ser.YValue[index] ]);  end;end;  If data are provided by an external chartsource you query them from there, again ATool.PointIndex is the index of the data point. You wrote somewhere that you have the data in an array. Then you probably use a TUserDefinedChartSource to link to array to the series. In this case you can call the OnGetChartDataItem event handler to find the x,y values. ---------------------------------------------------------------------- kinlion · 2018-12-07 15:57 Quote from: wp on December 07, 2018, 10:34:58 amA better way is to directly read the x,y values from the series or the chart source. If your data are stored in the internal listsource of the lineseries you can simply call ser.XValue[index] and ser.YValue[index] where index is the series point index returned by ther chart tool (ser.PointIndex): ser.PointIndex helps to resolve the problem. Thanks wp btw, how to mark this topic as RESOLVED ? ---------------------------------------------------------------------- wp · 2018-12-07 16:17 Edit the title of the first post and add "[SOLVED]" in front of the title.