Legend with check boxes--when are they clicked?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Legend with check boxes--when are they clicked?

Post by TestAlways » Thu Dec 31, 2009 6:56 pm

I have a legend with check boxes turned on--I need to know when one of the check boxes is clicked. How can I know? (I can use the OnCLick event for the chart, but is there anything more narrow?)

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Legend with check boxes--when are they clicked?

Post by Yeray » Mon Jan 04, 2010 11:34 am

Hi Ed,

The most accurate I can think right now would be something as following:

Code: Select all

uses series, TeCanvas;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D:=false;

  for i:=0 to 4 do
  begin
    Chart1.AddSeries(TPointSeries.Create(self));
    Chart1[i].FillSampleValues();
  end;

  Chart1.Legend.CheckBoxes:=true;
end;

procedure TForm1.Chart1ClickLegend(Sender: TCustomChart;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i: Integer;
    tmpPnt: TPoint;
    tmpRect: TRect;
begin
  tmpPnt.X:=X;
  tmpPnt.Y:=Y;

  for i:=0 to Chart1.SeriesCount-1 do
  begin
    tmpRect.Left:=Chart1.Legend.Left;
    tmpRect.Right:=Chart1.Legend.Left + Chart1.Legend.Width - 1;
    tmpRect.Bottom:=Chart1.Legend.Item[i].Top + Chart1.Legend.Item[i].SymbolRect.Bottom - Chart1.Legend.Item[i].SymbolRect.Top + 3;

    if (i = 0) then tmpRect.Top:=Chart1.Legend.Item[i].Top-3
    else tmpRect.Top:=Chart1.Legend.Item[i].Top-2;

    if PtInRect(tmpRect,tmpPnt) then
    begin
      showmessage('series ' + IntToStr(i+1));
      break;
    end;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply