在一个小型的Delphi程序中,我在运行时以编程方式创建很少的TCharts和TBarSeries,但随后我希望能够单击图表的条形并触发例如Chart1ClickSeries事件以显示该条的信息。这可能吗??
首先,创建事件处理程序:
TForm1 = class...
...
procedure BarSeries1Click(Sender: TChartSeries;
ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
procedure BarSeries1DblClick(Sender: TChartSeries;
ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
...
end;
procedure TForm1.BarSeries1Click(Sender: TChartSeries;
ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
ShowMessage('Click');
end;
procedure TForm1.BarSeries1DblClick(Sender: TChartSeries;
ValueIndex: Integer; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
ShowMessage('DblClick');
end;
然后,在创建系列后,分配事件:
BarSeries1.OnClick:=BarSeries1Click;
BarSeries1.OnDblClick:=BarSeries1DblClick;