Contents page 
  Previous | Next 
 

Tutorial 8 - Zoom and Scroll


Zoom and Scroll are useful aids for focusing on specific data in a densely populated Chart. See the Visual Basic example code in folders 'Animated Zoom' and 'Scrolling'.

Contents

How to Zoom and Scroll using the Mouse

Zoom
Scroll

How to Zoom and Scroll by code

Zoom
Animated Zoom
Zoom events
Scroll


How to Zoom and Scroll using the Mouse

Zoom

To zoom in on a Chart, press the right mousebutton at the top left hand corner of the area you wish to zoom in on and, maintaining the mousebutton pressed, drag out the rectangle to the bottom righthand corner of the zoom area. Releasing the mousebutton will force the Chart to redraw the area selected.

To undo the zoom, press the left mousebutton anywhere on the Chart area and drag up and left with the mousebutton depressed. Releasing the button will force the Chart to redraw to the originally defined Chart area.

Scroll

To scroll a Chart across, press the left mousebutton and, maintaining the mousebutton pressed, drag the mouse in the direction you wish to scroll the Chart. When you release the mousebutton the Chart will remain at the new location.

To undo the scroll, press the left mousebutton anywhere on the Chart area and drag up and left with the mousebutton depressed. Release the button and the Chart will redraw to the originally defined Chart area.

How to Zoom and Scroll by code

Zoom

Zoom is, by default, enabled. Use the Zoom.getAllow method to disable zoom.
See the Zoom Class for a full list of methods associated with Zoom. To define a rectangular area over which to Zoom use the ZoomRect method.
 

Example

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

The ZoomRect co-ordinates are defined in screen pixels where 0,0 is the top left hand point of the Chart Panel. The following code will zoom in on an area between the 2nd and 5th x-axis points, setting the y-axis to the scale of the maximum and minimum points of the entire Chart:

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);

Use 'Undo' to Zoom back out.

tChart1.getZoom().undo();

Animated Zoom

Animated Zoom offers stepped zooming. Instead of jumping from 'zoomed out' to 'zoomed in' in one step, you may set AnimatedZoom to enabled and define staggered steps for the zoom. Once AnimatedZoom is enabled you may zoom manually with the Mouse or by code.

Example


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);

Zoom events

Zooming in manually, or by code, will trigger the TChart.Zoomed event. Zooming out will trigger the TChart.UndoneZoom event.


Scroll

Scroll is enabled in all directions as default. Use the Scroll.Allow property to disable Scroll or limit Scroll to one direction.
The easiest way to scroll by code is to use the Axis Scroll method:

Example

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

The value is the offset. 'False' refers to whether or not TeeChart will allow scrolling beyond Series value limits.

Another way to control scroll is to define Axis maximum and minumum to scroll by code:

 

Example

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()); 
}



© 1996-2008 Steema Software SL. All rights reserved.