0

我正在绘制趋势图(线),但在我的情况下,图例文本非常大,因此我可以通过任何方式对文本进行自动换行。

在此处输入图像描述

4

1 回答 1

0

我认为您可以使用可以在此链接中找到的字符串函数来操作系列的标题并尝试减少它们的长度。我提出了一个建议代码,我认为可以帮助您实现所需的目标:

Private Sub Form_Load()
    TChart1.Aspect.View3D = False
    TChart1.AddSeries scLine
    TChart1.AddSeries scLine
    Dim i As Integer
    TChart1.Series(0).AddXY 0, 30, "", clTeeColor
    TChart1.Series(0).AddXY 10, 100, "", clTeeColor
    TChart1.Series(1).AddXY 0, 50, "", clTeeColor
    TChart1.Series(1).AddXY 50, 120, "", clTeeColor
    TChart1.Series(0).Title = "DDDDAAAAFFFFLLLLRRRRSSSS"
    TChart1.Series(1).Title = "AAAALLLLSSSSTTTTEEEERRRR"
    SeriesTitleWarp TChart1.SeriesCount
End Sub

Private Sub SeriesTitleWarp(ByVal count As Long)
'Replace some chars of string title to ...
    Dim i As Integer
        For i = 0 To count - 1
            'Calculate the size of string
            Dim LenString As Integer
            LenString = Len(TChart1.Series(i).Title)
            'First replace the Left chars for ...
            Dim TitleString As String
            TitleString = TChart1.Series(i).Title
            Mid$(TitleString, 10, 3) = "..."
            'After cut the string
            TitleString = Left(TitleString, 12)
            'Assign new title to series.
            TChart1.Series(i).Title = TitleString
    Next i
End Sub

修改您的要求,我建议您使用另一种减少图例文本的替代方法,但系列标题保持不变。您能否检查下一个代码是否按您的意愿工作?

Private Sub Form_Load()
    TChart1.Aspect.View3D = False
    TChart1.AddSeries scLine
    TChart1.AddSeries scLine
    Dim i As Integer
    TChart1.Series(0).AddXY 0, 30, "", clTeeColor
    TChart1.Series(0).AddXY 10, 100, "", clTeeColor
    TChart1.Series(1).AddXY 0, 50, "", clTeeColor
    TChart1.Series(1).AddXY 50, 120, "", clTeeColor
    TChart1.Series(0).Title = "DDDDAAAAFFFFLLLLRRRRSSSS"
    TChart1.Series(1).Title = "AAAALLLLSSSSTTTTEEEERRRR"
  '  TChart1.Legend.ShapeBounds.Right = 100
    TChart1.Legend.Left = 100
    TChart1.Legend.CustomPosition = True
    TChart1.Legend.Width = 100
End Sub

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
        If ValueIndex <> -1 Then
            'Calculate the size of string
            Dim LenString As Integer
            LenString = Len(TChart1.Series(ValueIndex).Title)
            'First replace the Left chars for ...
            Dim TitleString As String
            TitleString = TChart1.Series(ValueIndex).Title
            Mid$(TitleString, 10, 3) = "..."
            'After cut the string
            TitleString = Left(TitleString, 12)
            'Assign new text to LegendText
            LegendText = TitleString
        End If
End Sub

我希望会有所帮助。

谢谢。

于 2013-08-14T09:27:18.063 回答