Displaying legend at the right side centre of the Chart

TeeChart for ActiveX, COM and ASP
Post Reply
Faizullah Khan
Newbie
Newbie
Posts: 50
Joined: Wed Apr 26, 2006 12:00 am

Displaying legend at the right side centre of the Chart

Post by Faizullah Khan » Mon May 08, 2006 4:12 pm

Hello,

I want to display the legend at the right side centre of the Chart
I set the custom position of the Legends,But when i change the Scales then they displaced.

Regards

Faizullah Khan

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

Post by Narcís » Tue May 09, 2006 8:52 am

Hi Faizullah,

It works fine for me here using something like this:

Code: Select all

Private Sub Form_Load()
    TChart1.Series(0).FillSampleValues 10
        
    Me.ScaleMode = vbPixels
    TChart1.Legend.CustomPosition = True
    TChart1.Environment.InternalRepaint
End Sub

Private Sub TChart1_OnAfterDraw()
    TChart1.Legend.Left = TChart1.Width / 2
    TChart1.Legend.Top = TChart1.Top + 50
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

Faizullah Khan
Newbie
Newbie
Posts: 50
Joined: Wed Apr 26, 2006 12:00 am

Displaying legend at the right side middle of the Chart

Post by Faizullah Khan » Tue May 09, 2006 9:38 am

Hi,

Thanks it works fine as You understood but my requirement is that I want to display legend right side outside the chart scale area (Right Align at Middle )

Regard ,

Faizullah Khan

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

Post by Narcís » Tue May 09, 2006 10:01 am

Hi Faizullah,

I'm still not sure about what you are exactly trying to achieve. You can try if the code below does what you request. If it doesn't could you please extend on your request and if possible send us an image so that I can exactly understand what you want to draw?

You can post your files at news://www.steema.net/steema.public.attachments newsgroup.

Code: Select all

Dim LegendLeft As Integer

Private Sub Form_Load()
    TChart1.Series(0).FillSampleValues 10
    
    Me.ScaleMode = vbPixels
    LegendLeft = 0
    TChart1.Environment.InternalRepaint
End Sub

Private Sub TChart1_OnAfterDraw()
    Dim LegendHeight As Integer
    
    With TChart1.Legend
        If (LegendLeft = 0) Then
            LegendLeft = .Left
        End If
        
        LegendHeight = .ShapeBounds.Bottom - .ShapeBounds.Top
        
        .CustomPosition = True
        .Left = LegendLeft
        .Top = (TChart1.Height / 2) - (LegendHeight / 2)
        
        TChart1.Panel.MarginUnits = muPixels
        TChart1.Panel.MarginRight = (TChart1.Width - .Left) + _
                                    (TChart1.Width - .ShapeBounds.Right)
    End With
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

Faizullah Khan
Newbie
Newbie
Posts: 50
Joined: Wed Apr 26, 2006 12:00 am

Displaying legend at the right side centre of the Chart

Post by Faizullah Khan » Mon May 22, 2006 5:51 am

Hi

Legends problem is almost solved by using this code .
1- Some time Panel Right Margin increases from legend size .

2 -On resizing the Vb 6.0 form follwing Error mesaage appear and form resizing is not possible "Not Enough Storage is available to process this commad".

Regards

Faizullah Khan

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon May 22, 2006 10:20 pm

Hi,

it works fine here (both issues) using the following code :

Code: Select all

Private Sub Form_Load()
With TChart1
    .Height = Form1.ScaleHeight
    .Width = Form1.ScaleWidth
    .Left = 0
    .Top = 0
    
    .AddSeries scLine
    .Series(0).FillSampleValues 10
    
    Me.ScaleMode = vbPixels
    LegendLeft = 0
    .Environment.InternalRepaint
End With
End Sub

Private Sub TChart1_OnAfterDraw()
    Dim LegendHeight As Integer
    With TChart1.Legend
        LegendHeight = .ShapeBounds.Bottom - .ShapeBounds.Top
        .CustomPosition = True
        .Left = TChart1.Width - (.ShapeBounds.Right - .ShapeBounds.Left) - 10
        .Top = (TChart1.Height / 2) - (LegendHeight / 2)

        TChart1.Panel.MarginUnits = muPixels
        TChart1.Panel.MarginRight = (TChart1.Width - .Left) + 10
    End With
End Sub

Private Sub Form_Resize()
With TChart1
    .Height = Form1.ScaleHeight
    .Width = Form1.ScaleWidth
    .Left = 0
    .Top = 0
End With
End Sub
Could you please check if it works fine for you ?

Post Reply