【TeeChart Pro ActiveX教程】(四):軸控制—附加軸和軸事件
(一)附加軸
1.1 復(fù)制軸
TeeChart提供5個(gè)軸與數(shù)據(jù)系列,Left,Right,Top,Bottom和Depth相關(guān)聯(lián)。向圖表添加新系列時(shí),可以定義系列應(yīng)與哪些軸相關(guān)(轉(zhuǎn)到“Series”選項(xiàng)卡“General”頁(yè)面)。您可以使用Axis Customdraw方法在圖表上的任何位置重復(fù)前4軸中的任何一個(gè)(或全部)。請(qǐng)注意,此方法會(huì)復(fù)制Axis,但不會(huì)添加新的自定義軸。
例:
'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將繪制新軸,一個(gè)水平,一個(gè)垂直位于圖表的中心。當(dāng)您滾動(dòng)圖表(用鼠標(biāo)右鍵拖動(dòng))時(shí),新的垂直軸將始終保持在圖表的中心,新的水平軸將垂直滾動(dòng)上下移動(dòng)。新軸是默認(rèn)軸的精確副本。
1.2 多個(gè)自定義軸
與PositionPercent和拉伸屬性一起,可以在圖表上的任何位置浮動(dòng)無(wú)限軸。滾動(dòng),縮放和軸命中檢測(cè)也適用于自定義創(chuàng)建的軸。現(xiàn)在可以通過(guò)圖表編輯器在設(shè)計(jì)時(shí)創(chuàng)建額外的軸,也可以在運(yùn)行時(shí)通過(guò)幾行代碼創(chuàng)建額外的軸:
通過(guò)圖表編輯器

TeeChart為您提供在設(shè)計(jì)時(shí)創(chuàng)建自定義軸的功能,使其能夠以TeeChart的T恤文件格式保存。要實(shí)現(xiàn)此目的,請(qǐng)打開(kāi)圖表編輯器并單擊Axis選項(xiàng)卡,然后選擇“+”按鈕添加自定義軸。然后選擇“Position”選項(xiàng)卡,確保突出顯示新的自定義軸。此頁(yè)面上的“Horizontal”復(fù)選框允許您將新的自定義軸定義為水平軸或?qū)?其保留為默認(rèn)垂直軸。如上所述,此頁(yè)面的其余部分和Axis頁(yè)面中的其他選項(xiàng)卡可用于更改自定義軸的比例,增量,標(biāo)題,標(biāo)簽,刻度,次刻度和位置。要將此新的自定義軸與所需的數(shù)據(jù)系列相關(guān)聯(lián),請(qǐng)選擇“Series”選項(xiàng)卡,然后轉(zhuǎn)到“General”頁(yè)面,其中下拉組合框“Horizontal Axis”和“Vertical Axis”將允許您根據(jù)先前是否定義選擇新的自定義軸它是垂直的或水平的。
通過(guò)代碼,例:
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屬性將新軸與圖表的整體關(guān)系定位。
StartPosition=50 EndPosition=100
這些數(shù)字表示為圖表矩形的百分比,其中0(零)(在垂直軸的情況下)為T(mén)op。這些屬性可以應(yīng)用于標(biāo)準(zhǔn)軸,以在圖表中創(chuàng)建完全分區(qū)的“SubCharts”,例:
With TChart1.Axis.Left
    .StartPosition = 0
    .EndPosition = 50
    .Title.Caption = "1st Left Axis"
    .Title.Font.Bold = True
End With
以上2個(gè)編碼示例與以下數(shù)據(jù)結(jié)合使用:
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事件提供運(yùn)行時(shí)靈活性,可以修改Axis標(biāo)簽并在Axis Clicks上顯示用戶交互性。
OnClickAxis
例:
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
OnGetAxisLabel
可用于修改Axis標(biāo)簽,例:
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
OnGetNextAxisLabel
可用于決定應(yīng)顯示哪些軸標(biāo)簽,使用MoreLabels Boolean屬性來(lái)包含/排除軸標(biāo)簽,例:
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
購(gòu)買(mǎi)TeeChart Pro AciveX正版授權(quán),請(qǐng)點(diǎn)擊“”喲!

 QQ交談
QQ交談 在線咨詢(xún)
在線咨詢(xún) 
                 
                
 渝公網(wǎng)安備
            50010702500608號(hào)
渝公網(wǎng)安備
            50010702500608號(hào)
             
            
 客服熱線
客服熱線