Legend Position

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 Position

Post by TestAlways » Tue Nov 30, 2010 2:06 pm

I need the legend to be to the right of the chart, but I want it to be aligned to the bottom rather than the top of the chart.

How can I do that?

Thanks,

Ed Dressel

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

Re: Legend Position

Post by Yeray » Tue Nov 30, 2010 4:12 pm

Hi Ed,

You could place your legend manually like following:

Code: Select all

uses series;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to 4 do
    with Chart1.AddSeries(TBarSeries) do FillSampleValues;

  Chart1.Draw;

  Chart1.MarginUnits:=muPixels;
  Chart1.MarginRight:=100;
  Chart1.Legend.CustomPosition:=true;
  Chart1.Legend.Left:=Chart1.Width-Chart1.Legend.Width-10;
  Chart1.Legend.Top:=Chart1.Axes.Bottom.PosAxis-Chart1.Legend.Height-10;
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

TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Re: Legend Position

Post by TestAlways » Tue Nov 30, 2010 4:36 pm

This works until I resize the chart--the legend stays in the same location.

I tried some before/after draw events, and they did not work.

Any suggestions?

Ed Dressel

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

Re: Legend Position

Post by Sandra » Wed Dec 01, 2010 3:40 pm

Hello Ed,

I have done next example using OnAfterDraw event and works fine for me.

Code: Select all

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  Chart1.Legend.CustomPosition:=true;
  Chart1.Legend.Left:=Chart1.Width-Chart1.Legend.Width-10;
  Chart1.Legend.Top:=Chart1.Axes.Bottom.PosAxis-Chart1.Legend.Height-10;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to 4 do
    with Chart1.AddSeries(TBarSeries) do FillSampleValues;

  Chart1.Align:= alClient;
  Chart1.MarginUnits:=muPixels;
  Chart1.MarginRight:=100;

  Chart1.Draw;
end;
Could you please, tell us if previous code works as you want? If code doesn't work fine for you please, explain us which is the exactly problem.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

TestAlways
Advanced
Posts: 228
Joined: Tue Aug 28, 2007 12:00 am
Location: Oregon, USA

Re: Legend Position

Post by TestAlways » Wed Dec 01, 2010 4:16 pm

The attached demo (using 8.06) draws the legend in the wrong location the first time. After a redraw, it works fine.

Ed D
Attachments
Legend Location 2.zip
(2.99 KiB) Downloaded 507 times

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

Re: Legend Position

Post by Sandra » Fri Dec 03, 2010 11:50 am

Hello TestAlways,

If you want that legend location would be correct the first time, you need added Chart1.Draw twice in from create as do in next lines of code:

Code: Select all

constructor TForm2.Create(aOnwer: TComponent);
begin
  inherited;
  Series1.FillSampleValues(20);
  Series2.FillSampleValues(20);
  Series2.Title := 'this is a long description';
  Chart1.MarginUnits:=muPixels;
 Chart1.Draw;
 Chart1.Draw;
//  Chart1.MarginRight:=100;

end;
I also inform you, there is recent version of TeeChartVCL(8.07) you can download it here.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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