Legend custom position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
johnnix
Newbie
Newbie
Posts: 34
Joined: Tue Sep 18, 2018 12:00 am

Legend custom position

Post by johnnix » Fri Feb 01, 2019 1:31 pm

Hello,

I have an issue with placing the legend in a custom position, I have some code set inside the OnGetLegendRect to set the Rect position but I need to get an axis IAxisSize (I have a custom bottom axis). Once my application loads data to the plot the legend appears a little off position but once I move the mouse over the plot the legend jumps back to the correct position. Is there a way to make the chart recalculate the values IStartPos, IStartEnd etc?

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

Re: Legend custom position

Post by Yeray » Mon Feb 11, 2019 9:48 am

Hello,

You probably need to force a chart repaint so some internal properties are calculated the second time the OnGetLegendRect event is fired.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
//...
  Chart1.Draw;
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

johnnix
Newbie
Newbie
Posts: 34
Joined: Tue Sep 18, 2018 12:00 am

Re: Legend custom position

Post by johnnix » Thu Feb 28, 2019 6:10 am

Hello,

Thank you for your reply, I already tried that, has an affect on the position of the legend but it still moves once the mouse pasts over the plot.

Regards

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

Re: Legend custom position

Post by Yeray » Thu Feb 28, 2019 9:01 am

Hello,

If you could send us a simple example project to reproduce the problem here it could help us to provide a fix/workaround.
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

johnnix
Newbie
Newbie
Posts: 34
Joined: Tue Sep 18, 2018 12:00 am

Re: Legend custom position

Post by johnnix » Fri Mar 01, 2019 2:55 pm

Hello,

It looks like I cannot reproduce the issue outside my application so I would like to ask this question, I need the legend rectangle to be drawn in a specific position inside the chart area for example 20 pixels above bottom axis and 20 pixels right of the left axis (plot can be empty of data but there is always at least 1 line series attached)

Regards

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

Re: Legend custom position

Post by Yeray » Fri Mar 01, 2019 4:04 pm

Hello,

You could use the Legend in CustomPosition. Ie:

Code: Select all

uses Series;

procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
begin
  Chart1.Legend.CustomPosition:=True;
  Chart1.Legend.Left:=TChart(Sender).ChartRect.Left+20;
  Chart1.Legend.Top:=TChart(Sender).ChartRect.Bottom-20-Chart1.Legend.Height;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Legend.LegendStyle:=lsSeries;
  Chart1.AddSeries(TLineSeries);

  Chart1.Draw;
end;
The only problem is the ChartRect is defined later than than the Legend drawing. That's why you should make sure the chart has been redrawn before using ChartRect to set the Legend position.
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

Post Reply