So to try to get this to work, I tried setting “Chart1.Legend.CustomPosition := True” in the OnCreate of my form. And then I used the following OnGetLegendRect procedure for Chart1.
Code: Select all
procedure TfrmMain.Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
begin
Sender.Legend.Left := Trunc((Sender.Width – (Rect.Right – Rect.Left)) / 2);
Sender.Legend.Right := Trunc((Sender.Height – (Rect.Bottom – Rect.Top)) / 2);
end;
Can you please help me understand what I might be doing wrong with this method?
Alternatively, I tried the following:
Code: Select all
procedure TfrmMain.Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
var
iLegendWidth, iLegendHeight: Integer;
begin
iLegendWidth := Rect.Right – Rect.Left;
iLegendHeight := Rect.Bottom – Rect.Top;
Rect.Left := Trunc((Sender.Width – iLegendWidth) / 2);
Rect.Right := Rect.Left + iLegendWidth;
Rect.Top := Trunc((Sender.Height – iLegendHeight) / 2);
Rect.Bottom := Rect.Top + iLegendHeight;
end;
Thanks!