TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
Metek
- Newbie
- Posts: 9
- Joined: Mon Nov 02, 2020 12:00 am
- Location: Germany
-
Contact:
Post
by Metek » Thu Jul 27, 2023 9:19 am
Hi,
I want to show the legend always at the TopLeft of the chart rect:
Code: Select all
Chart1.Legend.Left := Chart1.ChartRect.Left;
Chart1.Legend.Top := Chart1.ChartRect.Top;
The chart is aligned to alClient of the main window, Legend.CustomPosition is set to true and Legend. PositionUnits is set to muPixels.
But where do I place the code to be executed after resizing the chart?
It seems to work best within OnBeforeDrawSeries, but not after maximising / restoring the window.
Can you please help?
Kind regards
Metek
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Fri Jul 28, 2023 6:50 am
Hello,
You may be missing to force a
Legend.CalcRect
. This works fine for me:
Code: Select all
uses Chart, TeEngine, TeeProcs, Series;
var Chart1: TChart;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1:=TChart.Create(Self);
with Chart1 do
begin
Parent:=Self;
Align:=alClient;
Color:=clWhite;
Gradient.Visible:=False;
Walls.Back.Color:=clWhite;
Walls.Back.Gradient.Visible:=False;
View3D:=False;
AddSeries(TFastLineSeries).FillSampleValues;
AddSeries(TFastLineSeries).FillSampleValues;
Legend.PositionUnits:=muPixels;
Legend.CustomPosition:=True;
OnBeforeDrawSeries:=ChartBeforeDrawSeries;
end;
end;
procedure TForm1.ChartBeforeDrawSeries(Sender: TObject);
begin
RepositionLegend;
end;
procedure TForm1.RepositionLegend;
begin
Chart1.Legend.Left:=Chart1.ChartRect.Left;
Chart1.Legend.Top:=Chart1.ChartRect.Top;
Chart1.Legend.CalcRect;
end;
-
Metek
- Newbie
- Posts: 9
- Joined: Mon Nov 02, 2020 12:00 am
- Location: Germany
-
Contact:
Post
by Metek » Mon Jul 31, 2023 12:20 pm
Thank you, that was it.
Kind regards
Metek