Extra legend tool position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
stsl
Newbie
Newbie
Posts: 45
Joined: Thu Jun 21, 2007 12:00 am

Extra legend tool position

Post by stsl » Mon Feb 23, 2009 5:31 am

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

johnnix
Advanced
Posts: 192
Joined: Tue Jul 10, 2007 12:00 am

Post by johnnix » Mon Feb 23, 2009 6:34 am

Hello,

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;
Regards

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

Post by Yeray » Mon Feb 23, 2009 10:21 am

Hi stsl,
stsl wrote:How is it possible to position correctly the Extra legend tool when the window is resized ?
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.
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:

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;
stsl wrote:I tried with the Chart OnResize event but this event is never fired.
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.
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

stsl
Newbie
Newbie
Posts: 45
Joined: Thu Jun 21, 2007 12:00 am

Post by stsl » Tue Feb 24, 2009 9:00 am

Hi, it works very well.

I made a mistake in my code, it was the reason why the OnResize was not fired (i loaded a template and lost my design time event)

Best regards

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

Post by Yeray » Tue Feb 24, 2009 11:00 am

Hi stsl,

I'm happy to see that you solved it!
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

stsl
Newbie
Newbie
Posts: 45
Joined: Thu Jun 21, 2007 12:00 am

Post by stsl » Mon Mar 02, 2009 1:02 pm

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

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

Post by Yeray » Mon Mar 02, 2009 3:02 pm

Hi stsl,

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;
Of course you should define as global integer the MaxLegendWidth and initialize it to zero at OnCreate, for example.
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

stsl
Newbie
Newbie
Posts: 45
Joined: Thu Jun 21, 2007 12:00 am

Post by stsl » Mon Mar 02, 2009 4:25 pm

Hi,

I tried this solution with a long text in the second legend (long group serie title). The Chart panel is not correctly resized. The 2 legends are truncated.

Regards

stsl
Newbie
Newbie
Posts: 45
Joined: Thu Jun 21, 2007 12:00 am

Post by stsl » Mon Mar 02, 2009 8:52 pm

I sent a file from your upload page (Test TimeGraph.7z).
In my sample, there is an other problem when i resize the chart too quickly (i joined a png file to see my 2 problems)

Best regards

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

Post by Yeray » Wed Mar 04, 2009 11:58 am

Hi stsl,

I've sent to your mail your project with the changes I made to solve these issues.
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

stsl
Newbie
Newbie
Posts: 45
Joined: Thu Jun 21, 2007 12:00 am

Post by stsl » Wed Mar 04, 2009 1:06 pm

Thanks, it's really better.
But the legend is now in front of the right axis. How is possible to have the the 2 legends between the labels of the right axis and the right side of the chart panel (with a little margin) like the default legend position of a new chart ?

Best regards

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

Post by Yeray » Thu Mar 05, 2009 8:37 am

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:

Code: Select all

Chart.MarginRight := Chart.Width-Chart.Legend.Left;
And at OnCreate:

Code: Select all

Chart.MarginUnits := muPixels;
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