我正在绘制一个趋势图表(行),但在我的情况下,图例文本非常大,所以我可以用任何方式对文字进行自动换行。
答案 0 :(得分:0)
我认为您可以使用此link中可以找到的字符串函数来操作系列的标题并尝试减少它们的长度。我已经提出了一个我认为可以帮助您实现的建议代码:
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
我希望能有所帮助。
感谢。