1. 程式人生 > >【TeeChart Pro ActiveX教程】(十一):縮放和滾動

【TeeChart Pro ActiveX教程】(十一):縮放和滾動

下載TeeChart Pro ActiveX最新版本

如何使用滑鼠進行縮放和滾動

縮放

要放大圖表,請在要放大的區域的左上角按住滑鼠左鍵並按住滑鼠按鈕,將矩形拖動到縮放區域的右下角。釋放滑鼠按鈕,圖表將重繪所選區域。 要撤消縮放,請在“Chart”區域的任意位置按滑鼠左鍵,然後按住滑鼠按鈕向上和向左拖動。釋放按鈕,圖表將重繪為最初定義的圖表區域。

縮放

要滾動圖表,按右滑鼠按鈕並按住滑鼠按鈕,將滑鼠拖動到您想要滾動圖表的方向。釋放滑鼠按鈕時,圖表將保留在新位置。 要撤消滾動,請在“Chart”區域的任意位置按滑鼠左鍵,然後按住滑鼠按鈕向上和向左拖動。釋放按鈕,圖表將重繪為最初定義的圖表區域。

如何通過程式碼縮放和滾動

預設情況下啟用縮放縮放。使用Zoom.Allow屬性禁用縮放。有關與縮放關聯的屬性和方法的完整列表,請參見縮放類。要定義縮放的矩形區域,請使用ZoomRect方法。

[C#]

tChart1.Zoom.ZoomRect(new Rectangle(100,100,120,120));

[VB.Net]

TChart1.Zoom.ZoomRect(New Rectangle(100, 100, 120, 120))

ZoomRect座標以螢幕畫素定義,其中0,0是圖表面板的左上角。 以下程式碼將放大第2和第5個x軸點之間的區域,將y軸設定為整個圖表的最大和最小點的比例:

[C#]

int x = points1.CalcXPos(2); 
int y = tChart1.Axes.Left.CalcYPosValue(tChart1.Axes.Left.MaxYValue); 
int height = tChart1.Axes.Left.CalcYPosValue(tChart1.Axes.Left.MinYValue) - tChart1.Axes.Left.CalcYPosValue(tChart1.Axes.Left.MaxYValue); 
int width = points1.CalcXPos(5) - x; 
Rectangle r = new Rectangle(x,y,width,height); 
tChart1.Zoom.ZoomRect(r);

[VB.Net]

Dim X As Integer = Points1.CalcXPos(2) 
Dim Y As Integer = TChart1.Axes.Left.CalcYPosValue(TChart1.Axes.Left.MaxYValue) 
Dim Height As Integer = TChart1.Axes.Left.CalcYPosValue(TChart1.Axes.Left.MinYValue) - TChart1.Axes.Left.CalcYPosValue(TChart1.Axes.Left.MaxYValue) 
Dim Width As Integer = Points1.CalcXPos(5) - X 
Dim R As New Rectangle(X, Y, Width, Height) 
TChart1.Zoom.ZoomRect(R)

使用“Undo”縮小。

TChart1.Zoom.Undo

動畫縮放

動畫縮放提供步進縮放。您可以將Animated設定為啟用併為縮放定義交錯步驟,而不是一步跳過“zoomed out”到“zoomed in”。啟用動畫後,您可以使用滑鼠或程式碼手動縮放,例

[C#]

int x = points1.CalcXPos(2); 
int y = tChart1.Axes.Left.CalcYPosValue(tChart1.Axes.Left.MaxYValue); 
int height = tChart1.Axes.Left.CalcYPosValue(tChart1.Axes.Left.MinYValue) - tChart1.Axes.Left.CalcYPosValue(tChart1.Axes.Left.MaxYValue); 
int width = points1.CalcXPos(5) - x; 
Rectangle r = new Rectangle(x,y,width,height); 
tChart1.Zoom.Animated = true; 
tChart1.Zoom.AnimatedSteps = 100; 
tChart1.Zoom.ZoomRect(r);

[VB.Net]

Dim X As Integer = Points1.CalcXPos(2) 
Dim Y As Integer = TChart1.Axes.Left.CalcYPosValue(TChart1.Axes.Left.MaxYValue) 
Dim Height As Integer = TChart1.Axes.Left.CalcYPosValue(TChart1.Axes.Left.MinYValue) - TChart1.Axes.Left.CalcYPosValue(TChart1.Axes.Left.MaxYValue) 
Dim Width As Integer = Points1.CalcXPos(5) - X 
Dim R As New Rectangle(X, Y, Width, Height) 
TChart1.Zoom.Animated = True 
TChart1.Zoom.AnimatedSteps = 100 
TChart1.Zoom.ZoomRect(R)

縮放事件

手動縮放或通過程式碼縮放將觸發TChart.Zoomed事件。預設情況下,縮小將觸發TChart.UndoneZoom事件。

滾動

滾動在所有方向上啟用。使用Scroll.Allow屬性禁用Scroll或將Scroll限制為一個方向。按程式碼滾動的最簡單方法是使用Axis Scroll方法:

[C#]

tChart1.Axes.Bottom.Scroll(3, false);

[VB.Net]

TChart1.Axes.Bottom.Scroll(3, False)

該值是偏移量。'False'指的是TeeChart是否允許滾動超出Series值限制。 控制滾動的另一種方法是定義Axis maximum和minumum以按程式碼滾動:

[C#]

private void Form1_Load(object sender, System.EventArgs e) { 
        int range = Convert.ToInt32(bar1.XValues.Maximum - bar1.XValues.Minimum / 2); 
        bar1.FillSampleValues(20); 
        tChart1.Panning.Allow = ScrollModes.None; 
        hScrollBar1.Value = range; 
        hScrollBar1.Minimum = range - 50; 
        hScrollBar1.Maximum = range + 50; 
} 
     
private void hScrollBar1_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) { 
        tChart1.Axes.Bottom.Automatic = false; 
        tChart1.Axes.Bottom.Minimum = e.NewValue; 
        tChart1.Axes.Bottom.Maximum = e.NewValue + bar1.Count; 
}

[VB.Net]

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
            Dim Range As Integer = Bar1.XValues.Maximum - Bar1.XValues.Minimum / 2 
            Bar1.FillSampleValues(20) 
            TChart1.Panning.Allow = Steema.TeeChart.ScrollModes.None 
            HScrollBar1.Value = Range 
            HScrollBar1.Minimum = Range - 50 
            HScrollBar1.Maximum = Range + 50 
End Sub 
 
Private Sub HScrollBar1_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll 
            TChart1.Axes.Bottom.Automatic = False 
            TChart1.Axes.Bottom.Minimum = e.NewValue 
            TChart1.Axes.Bottom.Maximum = e.NewValue + Bar1.Count 
End Sub