Extra legend tool position
Extra legend tool position
Hi,
How is it possible to position correctly the Extra legend tool when the window is resized ? I tried with the Chart OnResize event but this event is never fired.
How is it possible to modify the width of this Extra legend and to add a right margin (actually equal to 0) ?. I would like to have the same width like the normal legend.
Best regards
How is it possible to position correctly the Extra legend tool when the window is resized ? I tried with the Chart OnResize event but this event is never fired.
How is it possible to modify the width of this Extra legend and to add a right margin (actually equal to 0) ?. I would like to have the same width like the normal legend.
Best regards
Hello,
Try using the OnGetLegendRect event, I use this to custom place my legend :
Regards
Try using the OnGetLegendRect event, I use this to custom place my legend :
Code: Select all
procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart; var Rect: TRect);
var w, h: Integer;
begin
w:=Sender.Legend.Width;
h:=Sender.Legend.Height;
Sender.Legend.CustomPosition:=true;
Rect.Left:=Sender.ChartRect.Right-w-3;
Rect.Top:=Sender.ChartRect.Top+3;
Rect.Right:=Rect.Left+w;
Rect.Bottom:=Rect.Top+h;
end;
Hi stsl,
stsl wrote:How is it possible to position correctly the Extra legend tool when the window is resized ?
I'd like to recommend you something similar than what johnnix did, but considering that you have a "normal" legend and a extra legend tool and you don't want them to be superposed, you could do something like this:stsl wrote:How is it possible to modify the width of this Extra legend and to add a right margin (actually equal to 0) ?. I would like to have the same width like the normal legend.
Code: Select all
procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart;
var Rect: TRect);
begin
Rect.Left := Chart1.Legend.Left;
Rect.Right := Chart1.Legend.Left + Chart1.Legend.Width;
end;
procedure TForm1.Chart1Resize(Sender: TObject);
begin
Chart1.Draw;
ChartTool1.Legend.Top := Chart1.Legend.Top + Chart1.Legend.Height + 5;
end;
As you see, I've added the OnResize event on the sample project we discussed about in this thread and it seems to work fine. Please, could you send us a simple example project we can run "as-is" to reproduce the problem here? You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.stsl wrote:I tried with the Chart OnResize event but this event is never fired.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Hi stsl,
I'm happy to see that you solved it!
I'm happy to see that you solved it!
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Hi,
I have an other little problem with my Extra legend tool (one legend + one Extra legend Tool). I don't know how to find the extra legend tool width if this width is bigger than the normal legend width.
I would like to have the two legend with the same width equal to the max(legend width, extra legend width).
Best regards
I have an other little problem with my Extra legend tool (one legend + one Extra legend Tool). I don't know how to find the extra legend tool width if this width is bigger than the normal legend width.
I would like to have the two legend with the same width equal to the max(legend width, extra legend width).
Best regards
Hi stsl,
As OnGetLegendRect is executed for all the legends, you could get the biggest there doing something like this:
Of course you should define as global integer the MaxLegendWidth and initialize it to zero at OnCreate, for example.
As OnGetLegendRect is executed for all the legends, you could get the biggest there doing something like this:
Code: Select all
procedure TForm1.Chart1GetLegendRect(Sender: TCustomChart;
var Rect: TRect);
begin
if ((Rect.Right - Rect.Left) > MaxLegendWidth) then MaxLegendWidth := Rect.Right - Rect.Left;
Rect.Left := Chart1.Legend.Left;
Rect.Right := Chart1.Legend.Left + MaxLegendWidth;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Hi stsl,
I've sent to your mail your project with the changes I made to solve these issues.
I've sent to your mail your project with the changes I made to solve these issues.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Hi stsl,
It's because setting a custom legend position the chart margin is recalculated considering all the chartrect width.
You'll solve it setting a dynamic right margin respect the legend. For example:
At the end of ChartGetLegendRect:
And at OnCreate:
It's because setting a custom legend position the chart margin is recalculated considering all the chartrect width.
You'll solve it setting a dynamic right margin respect the legend. For example:
At the end of ChartGetLegendRect:
Code: Select all
Chart.MarginRight := Chart.Width-Chart.Legend.Left;
Code: Select all
Chart.MarginUnits := muPixels;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |