![]() |
Topics in this section include:
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:
begin
ShowMessage(' Clicked Series: '+Series.Name+' at point: '+ Floattostr(Series.XValue[valueindex]) + ',' + Floattostr(Series.YValue[valueindex]));
end;
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;
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;