I don't know what you want to happen you click.
A datapoint click tool is for clicking on a data point. Usually you provide a handler for its OnClick event. The event has the tool used (there may be other tools as well) as a parameter, but that is a very general TChartTool type (because the OnClick event is available also for aother chart tools). Therefore, you must cast it to TDataPointClickTool. The TDataPointClickTool, in turn, has a variety of properties which are set after the click and that you can query in the event handler:
- Series - the series clicked, again very general so that you must cast it to the type that you expect
- PointIndex - index of the clicked data point
- GraphPoint - coordinates of the point clicked
Modify the OnClick handler of your example in the following way, then a message box will popup whenever you click onto a datapoint:
procedure TForm1.ChartToolset1DataPointClickTool1PointClick(ATool: TChartTool;
APoint: TPoint);
var
tool: TDataPointClicktool;
series: TLineSeries;
begin
if not (ATool is TDataPointClickTool) then
exit;
tool := TDatapointClickTool(ATool);
if tool <> nil then begin
if not (tool.Series is TLineSeries) then
exit;
series := TLineSeries(tool.Series);
if series <> nil then
ShowMessage(
Format('Series "%s" clicked at data point #%d.'+LineEnding+'X is %f, and Y is %f',
[series.Title, tool.PointIndex, series.XValue[tool.PointIndex], series.YValue[tool.PointIndex]]
));
end;
end;
The tool requires a non-empty Shift combination to determine when it should become active. For a left-click, therefore, you must check the ssLeft element of the Shift property.
Since you must click on data points here, I'd recommend to display the data point symbols by setting the series' ShowPoints to true. Otherwise most clicks will miss the points.