Legend does not display when series title is too long

TeeChart for ActiveX, COM and ASP
Post Reply
cwdave
Newbie
Newbie
Posts: 42
Joined: Fri Nov 15, 2002 12:00 am

Legend does not display when series title is too long

Post by cwdave » Tue Feb 12, 2008 8:01 pm

TeeChart ActiveX 7.0.1.4.

When the length of any one Chart.Series(i).Title is longer in width than the width of the chart istself, the legend will not be displayed.

Is this a know issue? Is there a fix? If not, will there be one?
Is there a known workaround aside from truncating the offending series title? Can the series title be wrapped in the legend?


Thank you

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

Post by Narcís » Wed Feb 13, 2008 12:26 pm

Hi cwdave,

You can do as in the example below where OnGetLegendText event is used to shorten the text so that it fits into the chart width.

Code: Select all

Private Sub Form_Load()
    TChart1.Aspect.View3D = False
    
    TChart1.AddSeries scLine
    
    TChart1.Series(0).FillSampleValues 10
    TChart1.Series(0).Title = "Line series with quite a long title so that the legend is wider than ChartRect's and it is not displayed"

    TChart1.Legend.Alignment = laBottom
    TChart1.Legend.LegendStyle = lsSeries
    TChart1.Legend.Symbol.WidthUnits = lcsPixels
    TChart1.Legend.Shadow.Visible = False
End Sub

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
    CurrentSize = TChart1.Canvas.TextWidth(LegendText)
    RectWidth = (TChart1.Axis.Right.Position + TChart1.Aspect.Width3D) - TChart1.Axis.Left.Position

    Do While (CurrentSize > (RectWidth - TChart1.Legend.Symbol.Width - 20))
        LegendText = "" + Left(LegendText, Len(LegendText) - 1)
        CurrentSize = TChart1.Canvas.TextWidth(LegendText)
    Loop
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

Post Reply