Fixed legend position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
johnnix
Advanced
Posts: 192
Joined: Tue Jul 10, 2007 12:00 am

Fixed legend position

Post by johnnix » Sat Jan 10, 2009 9:40 am

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

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Post by Sandra » Mon Jan 12, 2009 9:51 am

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

johnnix
Advanced
Posts: 192
Joined: Tue Jul 10, 2007 12:00 am

Post by johnnix » Tue Jan 13, 2009 6:48 am

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

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

Post by Narcís » Tue Jan 13, 2009 8:47 am

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;
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