IOSTutorial10

From Steema Software Reference Wiki
Jump to: navigation, search

Net iphone.png

Contents page
Previous | Next

Tutorial10- Zoom and Scroll


Zoom and Scroll are useful aids for focusing on specific data in a densely populated Chart.  

How to Zoom and Scroll using the Gestures

Manual Zoom
There are two ways to zoom in on a Chart, it depends on the ZoomScrollStyle used, If 'manual' style is selected, by using the pinch gesture you will zoom in on the area selected. Releasing the fingers will cause the Chart to redraw the selected area.
To undo the zoom,  reverse the pinch gesture, dragging the fingers in towards each other.

Automatic Zoom
If Automatic ZoomScrollStyle is used then TeeChart will zoom and unzoom the Chart in standard iOS style as if the Chart were an image, thus increasing size and zooming into the chart as fingers are dragged apart on the screen and reversing the zoom as fingers are dragged together.

Scroll
To scroll a Chart across, tap with a finger and maintaining pressed, drag  in  the direction you wish to scroll the Chart. When you release the finger the Chart will remain at the new location.
To undo the scroll, tap over the screen anywhere on the Chart area and drag up and left with the finger. Release the finger and the Chart will redraw to the originally defined Chart area.

How to Zoom and Scroll by code

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

Example

[C#] 
tChart1.Zoom.ZoomRect(new 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:

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

Use 'Undo' to Zoom back out.

TChart1.Zoom.Undo

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

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

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:

[C#] 
tChart1.Axes.Bottom.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:

[C#] 
private void ViewDidLoad () {
        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;
}



PREVIOUS

NEXT


© 1998-2017 Steema Software SL. All rights reserved.