Page 1 of 1

Fixed legend position

Posted: Sat Jan 10, 2009 9:40 am
by 10046032
Hello all,

I am using version 8.04 and I need some hints on how to fix the legend position relative to top left point of the Y axis. I want to make sure that regardless the dimensions of my plots the legend is always inside the chart.

Regards

Posted: Mon Jan 12, 2009 9:51 am
by 10050769
Hi johnnix!!


You can solve the problem using event AfterDraw with the corresponent code, for exemple:

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var
  x,y:Integer;
begin
     Chart1.Legend.CustomPosition:=True;
     x:=Chart1.ChartRect.Left;
     y:=Chart1.ChartRect.Top;
     Chart1.Legend.Left:=x;
     Chart1.Legend.Top:=y;
end;

But, also you have to put next line to code in the FormCreate, but because don't draw legend to position indicated:

Code: Select all

Chart1.Draw;

Best Regards,
Sandra Pazos



Steema Support Central
http://support.steema.com

Posted: Tue Jan 13, 2009 6:48 am
by 10046032
Hello,

Than you for your reply. My issue with this code is that somewhere in my app I use the following code:

var m : TMetafile;
begin
if Sender.Name='pic1' then
begin
m := my_plot.TeeCreateMetafile(false,
Rect(0, 0, Round(Sender.Width), Round(Sender.Height)));

TfrxPictureView(Sender).Picture.Assign(m);
m.Free;
end;

This code assigns the plot metafile to a picture object of a FReport. After the code runs the legend makes a "jump" (moves a little bit) and I need to resize the plot in order to return to his original position. Obviously the AfterDraw procedure is called when calling the TeeCreateMetafile function.

Is there another way to do such a task using e.g. the OnGetLegendRect or OnGetLegendPos functions?

Regards

Posted: Tue Jan 13, 2009 8:47 am
by narcis
Hi johnnix,

Yes, you can do this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Draw;
end;

procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart;
  var Rect: TRect);
var w, h: Integer;
begin
  w:=Chart1.Legend.Width;
  h:=Chart1.Legend.Height;
  Chart1.Legend.CustomPosition:=true;
  Rect.Left:=Chart1.ChartRect.Left;
  Rect.Top:=Chart1.ChartRect.Top;
  Rect.Right:=Rect.Left+w;
  Rect.Bottom:=Rect.Top+h;
end;