Page 1 of 1

Legend Position

Posted: Tue Nov 30, 2010 2:06 pm
by 10546565
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

Re: Legend Position

Posted: Tue Nov 30, 2010 4:12 pm
by yeray
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;

Re: Legend Position

Posted: Tue Nov 30, 2010 4:36 pm
by 10546565
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

Re: Legend Position

Posted: Wed Dec 01, 2010 3:40 pm
by 10050769
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,

Re: Legend Position

Posted: Wed Dec 01, 2010 4:16 pm
by 10546565
The attached demo (using 8.06) draws the legend in the wrong location the first time. After a redraw, it works fine.

Ed D

Re: Legend Position

Posted: Fri Dec 03, 2010 11:50 am
by 10050769
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,