Page 1 of 1

Identify which chart send OnClick event

Posted: Fri Feb 17, 2017 6:44 pm
by 16579874
Dear reader,

I am developing a statistical application that performs clustering. Based on user input the program calculates a number of clusters and graphs the results. The charts are dynamically created at runtime and the number of graphs is not known in advance (varies from 2 - 50). The program works quite nicely but the charts lack support for user interaction. I want to be able to click on any of the charts and assign that chart to the TeeCommander for saving or editing. How can I identify/capture which of the charts triggered an OnClick event? Thank you for your support.

Re: Identify which chart send OnClick event

Posted: Mon Feb 20, 2017 1:57 pm
by yeray
Hello,

The TChart's OnClick event gives you the TChart that "sent" the event. So you can assign that Sender to the TTeeCommander's Panel property. Ie:

Code: Select all

uses Chart;

var Charts: array of TChart;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Setlength(Charts, 3);

  for i:=0 to High(Charts) do
  begin
    Charts[i]:=TChart.Create(Self);
    Charts[i].Parent:=Self;
    Charts[i].Align:=alTop;
    Charts[i].OnClick:=ChartOnClick;
  end;
end;

procedure TForm1.ChartOnClick(Sender: TObject);
begin
  TeeCommander1.Panel:=Sender as TChart;
end;

Re: Identify which chart send OnClick event

Posted: Tue Feb 21, 2017 4:38 pm
by 16579874
This works great! Thank you Yeray!