Determine Height of Legend

TeeChart for ActiveX, COM and ASP
Post Reply
tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Determine Height of Legend

Post by tirby » Mon Jan 05, 2015 7:13 pm

Hi,

I'm using version: TeeChart Pro v2013.0.1.4.131120

I have a Legend positioned at the bottom of the chart.
I'm trying to figure out the height of the legend based on the same scale as the chart.
What I'm seeing is that if I have the Legend set to invisible, the Chart is a specific height.
When I make the legend visible the Chart reduces in height to accommodate the legend.
I need to have the TChart get bigger in height, keeping the chart/grid the same vertical size.
The value of the Legend.Height is not the same scale as the TChart.height.
How can I determine the Legend height with respect to the TChart Height?

Thanks

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

Re: Determine Height of Legend

Post by Yeray » Wed Jan 07, 2015 8:57 am

Hi Tirby,

This simple example uses the ChartRect and the Legend properties (Left, Top and Right&Bottom or Width&Height) to draw a rectangle around both them.

Code: Select all

Private Sub Form_Load() 
  TChart1.AddSeries scLine
  TChart1.Series(0).FillSampleValues
  
  TChart1.Legend.Alignment = laBottom
End Sub

Private Sub TChart1_OnAfterDraw()
  With TChart1.Canvas
    .Brush.Style = bsClear
    .Pen.Color = vbRed
    
    .Rectangle TChart1.GetChartRect.Left, TChart1.GetChartRect.Top, TChart1.GetChartRect.Right, TChart1.GetChartRect.Bottom
    .Rectangle TChart1.Legend.Left, TChart1.Legend.Top, TChart1.Legend.Left + TChart1.Legend.Width, TChart1.Legend.Top + TChart1.Legend.Height
  End With
End Sub
I'm not sure about what are you exactly trying to achieve, but these properties may help you.
Otherwise, please don't hesitate to let us know and we'll try to help you.
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

tirby
Newbie
Newbie
Posts: 84
Joined: Mon Mar 16, 2009 12:00 am

Re: Determine Height of Legend

Post by tirby » Wed Jan 07, 2015 3:11 pm

Yeray,

Thank you for reviewing this.

On the picture below, I have place 2 screen-shots side by side.
I aligned the tops of the grids.
The picture on the left has the Legend set to invisible.
The picture on the right has the Legend set to visible.
Note the positions of the "0" lines.
The difference is highlighted by the purple lines and arrows.

What I need to have happen is regardless of the visible state of the Legend, the Height of the grid needs to remain the same.
Is this more clear now?

Thanks!
Attachments
Legend.png
Legend.png (17.39 KiB) Viewed 11374 times

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

Re: Determine Height of Legend

Post by Yeray » Thu Jan 08, 2015 2:53 pm

Hello,

Then, you should set the legend CustomPostition to true and set both the legend position and the chart margin manually. Ie:

Code: Select all

  TChart1.Aspect.View3D = False
  
  Dim i As Integer
  For i = 0 To 4
    TChart1.AddSeries scLine
    TChart1.Series(0).FillSampleValues
  Next i
  
  TChart1.Legend.Alignment = laBottom
  TChart1.Legend.CustomPosition = True
  
  TChart1.Environment.InternalRepaint
  TChart1.Legend.PositionUnits = puPixels
  TChart1.Legend.Top = TChart1.ChartBounds.Bottom - 30
  TChart1.Legend.Left = 80
  
  TChart1.Panel.MarginBottom = 10
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