Detect which series is being clicked when clicking legend

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Herman
Newbie
Newbie
Posts: 56
Joined: Tue Dec 07, 2004 5:00 am

Detect which series is being clicked when clicking legend

Post by Herman » Fri Apr 01, 2005 7:58 am

when user click in the legend area. Suppose i have 5 series, how to detect which series is being clicked.

thank you

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Apr 01, 2005 8:46 am

Hi Herman,

You can use the chart's OnClickLegend event. Using the Clicked method you will get the series index starting at 0 and with the index you will be able to address each sereis. This is a small example on how to use this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i:=0 to Chart1.SeriesCount-1 do
    begin
      Chart1[i].FillSampleValues();
      Chart1[i].SeriesColor:=clRed;
    end;
end;

procedure TForm1.Chart1ClickLegend(Sender: TCustomChart;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  SeriesIndex: Integer;
begin
  SeriesIndex:=Chart1.Legend.Clicked(X,Y);

  Chart1[SeriesIndex].SeriesColor:=clBlue;

  Chart1.Title.Text.Clear;
  Chart1.Title.Text.Add(IntToStr(SeriesIndex));
end;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply