Page 1 of 1

How to list legend items horizontally?

Posted: Mon Oct 02, 2006 3:43 am
by 9529132
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

Posted: Mon Oct 02, 2006 8:19 am
by narcis
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

Posted: Mon Oct 02, 2006 10:00 am
by 9529132
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

Posted: Mon Oct 02, 2006 10:11 am
by narcis
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.

Posted: Mon Oct 02, 2006 11:04 am
by 9529132
Got it. Thank you very much!