此次 表开发工具TeeChart Pro .NET使用教程将为大家带来如何缩放和滚动。
如何使用鼠标缩放和滚动
缩放
要放大图表,请在要放大的区域左上角按下鼠标左键并按住鼠标按钮,将矩形拖出到缩放区域的右下角。 释放鼠标按钮,图表将重绘所选区域。
要撤消缩放,请在图表区域的任意位置按鼠标左键,然后在按住鼠标键的同时向上和向左拖动。 松开按钮,图表将重新绘制到最初定义的图表区域。
滚动
要滚动图表,请按住鼠标右键并按住鼠标按钮,然后将鼠标朝您希望滚动图表的方向拖动。 当您释放鼠标按钮时,图表将保留在新位置。要撤消滚动,请在图表区域的任意位置按鼠标左键,然后在按住鼠标键的同时向上和向左拖动。 松开按钮,图表将重新绘制到最初定义的图表区域。
如何按代码缩放和滚动
缩放
默认情况下启用缩放。 使用 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) - XDim R As New Rectangle(X, Y, Width, Height)TChart1.Zoom.ZoomRect(R)
动画缩放
动画缩放提供阶梯式缩放。 您可以将动画设置为启用并为缩放定义交错的步骤,而不是一步从“缩小”跳到“放大”。 启用动画后,您可以使用鼠标或代码手动缩放。
[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) - XDim R As New Rectangle(X, Y, Width, Height)TChart1.Zoom.Animated = TrueTChart1.Zoom.AnimatedSteps = 100TChart1.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 是否允许滚动超出系列值限制。
控制滚动的另一种方法是通过代码定义要滚动的Axis最大值和最小值:
[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 + 50End SubPrivate 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.CountEnd Sub
如果您想了解TeeChart for .NET正版价格,欢迎咨询在线客服

标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!