Page 1 of 1

Legend does not display when series title is too long

Posted: Tue Feb 12, 2008 8:01 pm
by 9079199
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

Posted: Wed Feb 13, 2008 12:26 pm
by narcis
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