Page 1 of 1

TeeChart Legend

Posted: Tue Sep 20, 2016 1:25 pm
by 16479009
Is there a means of allowing the user to drag and resize the legend for a chart?

Re: TeeChart Legend

Posted: Wed Sep 21, 2016 9:37 am
by yeray
Hello,

You can do it manually using the mouse events. Ie:

Code: Select all

uses Series;

var legendDragging: Boolean;
    oldPos: TPoint;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.AddSeries(TBarSeries).FillSampleValues();

  legendDragging:=false;
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Chart1.Legend.Clicked(X, Y)>-1 then
  begin
    legendDragging:=True;
    oldPos:=Point(X,Y);
  end;
end;

procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  legendDragging:=False;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if Chart1.Legend.Clicked(X, Y)>-1 then
  begin
    Chart1.Cursor:=crHandPoint;
  end;

  if legendDragging then
  begin
    Chart1.Legend.CustomPosition:=true;
    Chart1.Legend.Left:=Chart1.Legend.Left+(X-oldPos.X);
    Chart1.Legend.Top:=Chart1.Legend.Top+(Y-oldPos.Y);
    oldPos:=Point(X,Y);
  end;
end;