翻譯|使用教程|編輯:王香|2018-11-06 11:03:11.000|閱讀 368 次
概述:TeeChart提供5個軸與數據系列,Left,Right,Top,Bottom和Depth相關聯。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
TeeChart提供5個軸與數據系列,Left,Right,Top,Bottom和Depth相關聯。向圖表添加新系列時,可以定義系列應與哪些軸相關(轉到“Series”選項卡“General”頁面)。您可以使用Axis Customdraw方法在圖表上的任何位置重復前4軸中的任何一個(或全部)。請注意,此方法會復制Axis,但不會添加新的自定義軸。
例:
'fill the Series for this example with random data Private Sub Command1_Click() Dim t As Integer For t = 0 To 20 TChart1.Series(0).AddXY t, ((100 * Rnd) + 1) - ((Rnd * 70) + 1), "", vbRed Next t End Sub 'Put this code in the TChart1_OnBeforeDrawSeries() event: Dim posaxis As Integer With TChart1 If .Axis.Left.Maximum > 0 Then 'When scrolling or on zoom always keep the gridlines enclosed in the Chart rectangle .Canvas.ClipRectangle .Canvas.Left, .Canvas.Top, (.Canvas.Left + .Canvas.Width), _ (.Canvas.Top + .Canvas.Height) 'Always draw the 2nd vertical Axis at the middle point of the Chart posaxis = (.Canvas.Left) + (.Canvas.Width * 0.5) .Axis.Left.CustomDraw posaxis - 10, posaxis - 20, posaxis, True 'Draw the 2nd Horizontal axis at the level of "10" on the vertical axis posaxis = (.Axis.Left.CalcYPosValue(10)) .Axis.Bottom.CustomDraw posaxis + 10, posaxis + 40, posaxis, True .Canvas.UnClipRectangle End If End With
自定義軸
在此示例中,TeeChart將繪制新軸,一個水平,一個垂直位于圖表的中心。當您滾動圖表(用鼠標右鍵拖動)時,新的垂直軸將始終保持在圖表的中心,新的水平軸將垂直滾動上下移動。新軸是默認軸的精確副本。
與PositionPercent和拉伸屬性一起,可以在圖表上的任何位置浮動無限軸。滾動,縮放和軸命中檢測也適用于自定義創建的軸。現在可以通過圖表編輯器在設計時創建額外的軸,也可以在運行時通過幾行代碼創建額外的軸:
TeeChart為您提供在設計時創建自定義軸的功能,使其能夠以TeeChart的T恤文件格式保存。要實現此目的,請打開圖表編輯器并單擊Axis選項卡,然后選擇“+”按鈕添加自定義軸。然后選擇“Position”選項卡,確保突出顯示新的自定義軸。此頁面上的“Horizontal”復選框允許您將新的自定義軸定義為水平軸或將其保留為默認垂直軸。如上所述,此頁面的其余部分和Axis頁面中的其他選項卡可用于更改自定義軸的比例,增量,標題,標簽,刻度,次刻度和位置。要將此新的自定義軸與所需的數據系列相關聯,請選擇“Series”選項卡,然后轉到“General”頁面,其中下拉組合框“Horizontal Axis”和“Vertical Axis”將允許您根據先前是否定義選擇新的自定義軸它是垂直的或水平的。
通過代碼,例:
Private Sub Command1_Click() TChart1.Series(0).VerticalAxisCustom = TChart1.Axis.AddCustom(False) 'You can modify any property of the new created axes, such as the axis color or axis title With TChart1.Axis.Custom(0) .AxisPen.Color = vbGreen .Title.Caption = "Extra axis" .Title.Font.Bold = True .Title.Angle = 90 .PositionPercent = 50 'percentage of Chart rectangle End With End Sub
然后,您可以使用StartPosition和EndPosition屬性將新軸與圖表的整體關系定位。
StartPosition=50 EndPosition=100
這些數字表示為圖表矩形的百分比,其中0(零)(在垂直軸的情況下)為Top。這些屬性可以應用于標準軸,以在圖表中創建完全分區的“SubCharts”,例:
With TChart1.Axis.Left .StartPosition = 0 .EndPosition = 50 .Title.Caption = "1st Left Axis" .Title.Font.Bold = True End With
以上2個編碼示例與以下數據結合使用:
For t = 0 To 10 TChart1.Series(0).AddXY t, 10 + t, "", clTeeColor If t > 1 Then TChart1.Series(1).AddXY t, t / 2, "", clTeeColor End If Next t
將顯示以下圖表:
多軸
Axis事件提供運行時靈活性,可以修改Axis標簽并在Axis Clicks上顯示用戶交互性。
例:
Private Sub TChart1_OnClickAxis(ByVal Axis As Long, ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long) 'Shows Axis point clicked when click on Bottom Axis. If Axis = atBottom Then MsgBox "Clicked Bottom Axis at " & TChart1.Axis.Bottom.CalcPosPoint(X) End If End Sub
可用于修改Axis標簽,例:
Private Sub TChart1_OnGetAxisLabel(ByVal aAxis As Long, ByVal SeriesIndex As Long, ByVal ValueIndex As Long, LabelText As String) 'Add following text to Bottom Axis Labels If aAxis = atBottom Then LabelText = "Period " + LabelText End If End Sub
可用于決定應顯示哪些軸標簽,使用MoreLabels Boolean屬性來包含/排除軸標簽,例:
Private Sub TChart1_OnGetNextAxisLabel(ByVal Axis As Long, ByVal LabelIndex As Long, LabelValue As Double, MoreLabels As Boolean) If Axis = atBottom Then MoreLabels = True 'Only label if following cases are true Select Case LabelIndex Case 0: LabelValue = 11 Case 1: LabelValue = 19 Case 2: LabelValue = 23 Case Else: MoreLabels = False End Select End If End Sub
購買TeeChart Pro AciveX正版授權,請點擊“”喲!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn