Page 1 of 1

Displaying legend at the right side centre of the Chart

Posted: Mon May 08, 2006 4:12 pm
by 9531181
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

Posted: Tue May 09, 2006 8:52 am
by narcis
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

Displaying legend at the right side middle of the Chart

Posted: Tue May 09, 2006 9:38 am
by 9531181
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

Posted: Tue May 09, 2006 10:01 am
by narcis
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

Displaying legend at the right side centre of the Chart

Posted: Mon May 22, 2006 5:51 am
by 9531181
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

Posted: Mon May 22, 2006 10:20 pm
by Pep
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 ?