Contents page |
Previous | Next
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'.
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.
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.
Zoom is, by default, enabled. Use the AllowZoom property to disable zoom. See the Chart Zooming for an alternative guide to 'How to' Zoom. To define a rectangular area over which to Zoom use the ZoomRect method:
Rect.Left := LineSeries1.CalcXPosValue( 22.5 ) ; Rect.Top := LineSeries1.CalcYPosValue( 5000 ) ; Rect.Right := LineSeries1.CalcXPosValue( 57.6 ) ; Rect.Bottom:= LineSeries1.CalcYPosValue( 15000 ) ; Chart1.ZoomRect( Rect );
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:
With Chart1 do begin ZoomRect(Rect(Axes.Bottom.CalcXPosValue(2), Axes.Bottom.CalcXPosValue(5), Axes.Left.CalcYPosValue(MaxYValue(Axes.Left)), Axes.Left.CalcYPosValue(MinYValue(Axes.Left)))); end;
Use 'Undo' to Zoom back out.
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.
With Chart1 do begin AnimatedZoom := True; AnimatedZoomSteps := 10; ZoomRect(Rect(Axes.Bottom.CalcXPosValue(2), Axes.Left.CalcYPosValue(MaxYValue(Axes.Left)), Axes.Bottom.CalcXPosValue(5), Axes.Left.CalcYPosValue(MinYValue(Axes.Left)))); end;
Zooming in manually, or by code, will trigger the Chart.OnZoom event. Zooming out will trigger the Chart.UndoZoom event.
As default Scroll is enabled for all directions. Use the AllowPanning property to disable Scroll or limit Scroll to one direction. You will need to define Axis maximum and minimum to scroll by code.
With Chart1 do begin AllowPanning := pmHorizontal; //permit manual scrolling horizontally only. Axes.Bottom.Automatic := False; Axes.Bottom.Minimum := 2; Axes.Bottom.Maximum := 5; end;
You could use scrollbars to change the Axis Minimum and Maximum values and thus control scrolling entirely by code. TeeChart Pro includes a ScrollBar component to make this easier. See the TChartScrollBar component for details. Manually, by code:
With Chart1 do AllowPanning := pmHorizontal; //permit manual scrolling horizontally only. Axes.Bottom.Automatic := False; //limit display to 5 points onscreen ChartScrollBar1.Chart := Chart1; ChartScrollBar1.Kind := sbHorizontal; ChartScrollBar1.Min := 0; ChartScrollBar1.Max := 20; End With