How to list legend items horizontally?

TeeChart for ActiveX, COM and ASP
Post Reply
David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

How to list legend items horizontally?

Post by David » Mon Oct 02, 2006 3:43 am

Hi,

I would like to list the legend items horizontally, not vertically. Then I would like to place the legend next to the header text. How to realize such a legend?

Thank you very much!
David

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Oct 02, 2006 8:19 am

Hi David,

You can use custom legend position doing something like this:

Code: Select all

Private Sub Form_Load()
    TChart1.Series(0).FillSampleValues 10    
    
    'InternalRepaint call to make the chart objects being drawn
    TChart1.Environment.InternalRepaint
    
    TChart1.Legend.Alignment = laTop
    TChart1.Legend.CustomPosition = True
    TChart1.Legend.Left = TChart1.Header.ShapeBounds.Right + 10
    TChart1.Legend.Top = TChart1.Header.ShapeBounds.Top
End Sub
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Mon Oct 02, 2006 10:00 am

Hi, Narcís,

Following your code, the legend is listed horizontally, but it is at the top left corner. Anything wrong? I figured out some code as

m_chart2.GetLegend().SetAlignment(laTop);
m_chart2.GetLegend().SetCustomPosition(TRUE);
long x = m_chart2.GetWidth()/2.0 - 50;
long y = m_chart2.GetHeader().GetShapeBounds().GetTop() + 24;
m_chart2.GetLegend().SetLeft(x);
m_chart2.GetLegend().SetTop(y);
And now it is listed right below the header text. Another question is when I should use the internal repaint? Under what circumstances should the repaint be used?

Thank you very much!
Daivd

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Oct 02, 2006 10:11 am

Hi David,

This is most likely to happen because you are not using InternalRepaint method. As I commented in my code snippet, this is used to force the chart being drawn so all elements have valid values as header shape bounds in that case as otherwise, since the chart hasn't been drawn those properties have not been set. This is necessary when setting properties like those in the OnFormLoad event for example, instead of in the OnAfterDraw event.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Mon Oct 02, 2006 11:04 am

Got it. Thank you very much!

Post Reply