【TeeChart for Java教程】(八)缩放和滚动

【下载TeeChart for Java最新版本】

(一)如何使用鼠标进行缩放和滚动

1.1 缩放

要放大图表,请在要放大的区域的左上角按鼠标右键,并按住鼠标按钮,将矩形拖动到缩放区域的右下角。释放鼠标按钮将强制图表重绘所选区域。 要撤消缩放,请在“Chart”区域的任意位置按鼠标左键,然后按住鼠标按钮向上和向左拖动。释放按钮将强制图表重绘为最初定义的图表区域。

1.2 滚动

要滚动图表,按下鼠标左键,并保持按下,拖动鼠标在你想滚动图表的方向。释放鼠标按钮时,图表将保留在新位置。 要撤消滚动,请在“Chart”区域的任意位置按鼠标左键,然后按住鼠标按钮向上和向左拖动。释放按钮,图表将重绘为最初定义的图表区域。

(二)如何通过代码缩放和滚动

2.1 缩放

默认情况下,启用缩放。使用Zoom.getAllow方法禁用缩放。要定义缩放的矩形区域,请使用ZoomRect方法,例:

tChart1.getZoom().zoomRect(new com.steema.teechart.Rectangle(100,100,120,120));

ZoomRect坐标以屏幕像素定义,其中0,0是图表面板的左上角。以下代码将放大第2和第5个x轴点之间的区域,将y轴设置为整个图表的最大和最小点的比例:

int x = points1.calcXPos(2); 
int y = tChart1.getAxes().getLeft().calcYPosValue(tChart1.getAxes().getLeft().getMaxYValue()); 
int height = tChart1.getAxes().getLeft().calcYPosValue(tChart1.getAxes().getLeft().getMinYValue()) - 
tChart1.getAxes().getLeft().calcYPosValue(tChart1.getAxes().getLeft().getMaxYValue()); 
int width = points1.calcXPos(5) - x; 
com.steema.teechart.Rectangle r = new com.steema.teechart.Rectangle(x,y,width,height); 
tChart1.getZoom().zoomRect(r);

使用“Undo”缩小:

tChart1.getZoom().undo();

2.2 动画缩放

动画缩放提供步进缩放。您可以将AnimatedZoom设置为启用并定义缩放的交错步骤,而不是一步跳过“缩小”到“放大”。启用AnimatedZoom后,您可以使用鼠标或代码手动缩放,例:

int x = points1.calcXPos(2); 
int y = tChart1.getAxes().getLeft().calcYPosValue(tChart1.getAxes().getLeft().getMaxYValue()); 
int height = tChart1.getAxes().getLeft().calcYPosValue(tChart1.getAxes().getLeft().getMinYValue()) - 
tChart1.getAxes().getLeft().calcYPosValue(tChart1.getAxes().getLeft().getMaxYValue()); 
int width = points1.calcXPos(5) - x; 
com.steema.teechart.Rectangle r = new com.steema.teechart.Rectangle(x,y,width,height); 
tChart1.getZoom().setAnimated(true); 
tChart1.getZoom().setAnimatedSteps(100); 
tChart1.getZoom().zoomRect(r);

2.3 缩放事件

手动或通过代码放大将触发TChart.Zoomed事件,缩小将触发TChart.UndoneZoom事件。

2.4 滚动

默认情况下,滚动在所有方向上启用。使用Scroll.Allow属性禁用Scroll或将Scroll限制为一个方向。 按代码滚动的最简单方法是使用Axis Scroll方法:

tChart2.getAxes().getBottom().scroll(3, false);

该值是偏移量。'False'指的是TeeChart是否允许滚动超出系列值限制。 控制滚动的另一种方法是定义Axis maximum和minumum以按代码滚动:

private void Load() {
        int range = com.steema.teechart.Utils.Round((bar1.getXValues().getMaximum() - bar1.getXValues().getMinimum() / 2)); 
        bar1.fillSampleValues(20); 
        tChart1.getPanning().setAllow(ScrollModes.NONE); 
        jScrollBar1.setValue(range); 
        jScrollBar1.setMinimum(range - 50); 
        jScrollBar1.setMaximum(range + 50); 
}

    public void jScrollBar1_propertyChange(PropertyChangeEvent evt) {
        tChart1.getAxes().getBottom().setAutomatic(false);         
        tChart1.getAxes().getBottom().setMinimum(jScrollBar1.getValue());
        tChart1.getAxes().getBottom().setMaximum(jScrollBar1.getValue() + bar1.getCount()); 
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值