在一个小的Delphi程序中,我在运行时以编程方式创建了几个TCharts和TBarSeries,但后来我希望能够单击图表的一个条并触发,例如,一个Chart1ClickSeries事件来显示该条的信息。那可能吗?
答案 0 :(得分:2)
首先,创建您的事件处理程序:
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;