Legend box positioning

TeeChart for ActiveX, COM and ASP
Post Reply
mpaulson
Newbie
Newbie
Posts: 41
Joined: Fri Nov 15, 2002 12:00 am

Legend box positioning

Post by mpaulson » Thu May 01, 2008 2:15 pm

Hi:

I would like to locate the legend box in the upper right of my graphs. I found the "left" and "top" attributes, but since the legend auto-sizes the width by how wide the text elements are, and there's no "width" attribute, I'm not sure how to proceed.

Do you have any suggestions?

Thanks,

Matt

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

Post by Yeray » Fri May 02, 2008 8:00 am

Hi Matt,

These properties give you the four legend corners:

Code: Select all

TChart1.Legend.ShapeBounds.Left
TChart1.Legend.ShapeBounds.Top
TChart1.Legend.ShapeBounds.Right
TChart1.Legend.ShapeBounds.Bottom
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

mpaulson
Newbie
Newbie
Posts: 41
Joined: Fri Nov 15, 2002 12:00 am

Post by mpaulson » Fri May 02, 2008 10:42 am

Thanks, I'll try that. But then what is TChart1.Legend.left and TChart1.Legend.top ?

mpaulson
Newbie
Newbie
Posts: 41
Joined: Fri Nov 15, 2002 12:00 am

Post by mpaulson » Fri May 02, 2008 10:48 am

Sorry, I have another related question: When these properties are set, are they used before or after the legend box is sized based on the width of the text elements?

Thanks,

Matt

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

Post by Yeray » Mon May 05, 2008 8:54 am

Hi Matt,

Yes, legend box is sized based on the width of the text elements. So, if you want to have the legend always at the same distance of the right of the chart, I recommend you to use them to obtain legend's width. And then, you could set legend's left property to move it. Something like this:

Code: Select all

Private Sub TChart1_OnResize()
  TChart1.Environment.InternalRepaint

  With TChart1.Legend
    .Left = TChart1.ChartBounds.Right - (.ShapeBounds.Right - .ShapeBounds.Left) - 5
  End With
End Sub
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

mpaulson
Newbie
Newbie
Posts: 41
Joined: Fri Nov 15, 2002 12:00 am

Post by mpaulson » Mon May 05, 2008 3:33 pm

Hi:

This method moved the legend, but causes the legend to be painted on top of the full width graph, which is ugly.

Normally the graph is sized to fit next to the legend. Is there a way to control this behaviour also?

Thanks,

Matt

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

Post by Yeray » Tue May 06, 2008 9:50 am

Hi Matt,

If you want to set a right margin according to the legend width, you could do as follows:

Code: Select all

Private Sub Form_Load()
  With TChart1
    .AddSeries scBar
  
    .Series(0).FillSampleValues 25
  
    .Legend.Top = 0

    TChart1_OnResize
    .Environment.InternalRepaint
    .Panel.MarginUnits = muPixels
  End With
  
  With TChart1.Legend.ShapeBounds
    TChart1.Panel.MarginRight = .Right - .Left + 15
  End With
End Sub

Private Sub TChart1_OnResize()
  TChart1.Environment.InternalRepaint

  With TChart1.Legend.ShapeBounds
    TChart1.Legend.Left = TChart1.ChartBounds.Right - (.Right - .Left) - 5
  End With
End Sub
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