TCustomChart.OnClickSeries
TCustomChart
property OnClickSeries: TChartClickSeries;
Unit
Chart
Description
An OnClickSeries event occurs whenever the user clicks onto any Chart TChartSeries.html">Series point. The Sender parameter specifies the Chart component that originated the event. The Series parameter is the corresponding clicked Series component, and the ValueIndex parameter refers to the exact clicked point in the Series. Series have also an OnClick event that can be used individually to catch clicked points. The Button, Shift, X and Y parameters determine the mouse button and mouse cursor coordinates at the time the Series point was clicked.
WARNING:
Use the CancelMouse property to control how the mouse button behaves with dual modes (scroll or zoom after an OnClickSeries event)
More on Chart Click events
Chart OnClickSeries
The TChart event, OnClickSeries, permits access to any active Series in your Chart. Put the following code into your project to get an idea of the possibilities. To access the event and add the procedure definition to your project, select your Chart and open the Object Inspector. Select the events tab to find OnClickSeries. Double-click on OnClickSeries.
procedure TForm1.DBChart1ClickSeries(Sender: TCustomChart;
Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ShowMessage(' Clicked Series: '+Series.Name+' at point: '+ IntToStr(ValueIndex));
end;
The valueindex refers to the index of the Series data point (point, bar, etc.) within the Chart. You may use it to access the X and Y value. For example:
ShowMessage(' Clicked Series: '+Series.Name+' at point: '+ Floattostr(Series.XValue[valueindex]) + ',' + Floattostr(Series.YValue[valueindex]));
Chart OnClick
You may use the OnClick event of the Chart to get the same information.
procedure TForm1.DBChart1Click(Sender: TObject);
var t,tmp : Integer;
x,y : Double;
begin
Series1.GetCursorValues(x,y);
for t:=0 to DBChart1.SeriesCount-1 do
begin
tmp:=DBChart1.Series[t].GetCursorValueIndex;
if tmp<>-1 then
ShowMessage(' Clicked Series: '+DBChart1.Series[t].Name+' at point: '+inttostr(tmp));
end;
end;
Series OnClick and OnDblClick
The Series OnClick event catches click events at Series level. Thus for multiple Series Charts you are able to restrict access to the data of a specific Series. To access the OnClick event of the Series you must select the Series in the Object Inspector and go to the events tab.
procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ShowMessage(' hello: '+Sender.Name+' at point: '+inttostr(valueindex));
end;