Legend onmouseover

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
lav1
Newbie
Newbie
Posts: 1
Joined: Tue Jan 15, 2013 12:00 am

Legend onmouseover

Post by lav1 » Wed Mar 20, 2013 9:47 pm

I have a Tchart with about a dozen Tlineseries standard x,y graph, legend has item for eac series with checkbox and series title. Is there a mouseover event on Legend so that if mouse is over the legend item associated with a series I can alter the colour of that series so it stands out from others
thanks
Sean

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

Re: Legend onmouseover

Post by Yeray » Thu Mar 21, 2013 4:10 pm

Hi Sean,

You can use the OnMouseMove event for it. You just have to calculate the rectangles of the according items in the legend and check if the mouse is over them.
Here is how you could do it:

Code: Select all

uses Series, TeCanvas;

var seriesIndex: Integer;

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

  for i:=0 to 11 do
  begin
    with Chart1.AddSeries(TFastLineSeries) as TFastLineSeries do
    begin
      FillSampleValues;
    end;
  end;

  seriesIndex:=-1;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var i: Integer;
    tmpR: TRect;
begin
  if PointInRect(Chart1.Legend.RectLegend, X, Y) then
  begin
    for i:=0 to Chart1.Legend.Items.Count-1 do
    begin
      tmpR:=Rect(Chart1.Legend.Left, Chart1.Legend.Items[i].Top,
                 Chart1.Legend.Left + Chart1.Legend.Width,
                 Chart1.Legend.Items[i].Top + Chart1.Canvas.textHeight('W'));

      if PointInRect(tmpR, X, Y) then
      begin
        if (seriesIndex<>-1) and (seriesIndex<>i) then
          Chart1[seriesIndex].Pen.Width:=1;

        seriesIndex:=i;
        Chart1[seriesIndex].Pen.Width:=2;
        break;
      end;
    end;
  end
  else
  begin
    if (seriesIndex>-1) then
      Chart1[seriesIndex].Pen.Width:=1;
    seriesIndex:=-1;
  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