Zooming and Scrolling
Overview
All X / Y Axes based charts (Bar, Line, Area, Candlestick, OHLC, Combinations, etc.) can have Axes with scroll bar. Robust, configurable scroll controls with the ability of external JS or Flex control.
There are two notes aboutr the current version: 3D charts and Logarithmic Axes can't be scrollable.
Turning Zoom and Scroll On/Off
Scroll is controlled for each axis in <zoom> node:
All these attrubutes are not used together, the set differs for Categorized Charts, for Linear Axes and Datetime axes.
Categorized axis
For categorized charts you can set the starting index and either number of categories to show, or the ending category:
This is a sample of bar chart with such settings:
Linear Axes
For linear axes you can set the starting value and either the range to show or ending value:
This is a sample of bar chart and Y Axis scrollable with such settings:
And this is a sample of scatter X/Y line with X Axis made scrollable:
Live sample:
Date Time Axes
For Date Time axes you can also set start date and end date, but when you define a range you should specify what units are used:
This is a sample of line chart with such settings:
JS Control
Set Scroll State Methods
You can control zoom and scroll using setXZoom and setYZoom JS Functions from JS Library. These functions have the differ use depending on the type of chart and axis, see available options and samples below.
Categorized Charts
Range in XML
Range in JS
Start End in XML
Start End in JS
Scatter Plot Charts with Number Axis
Start Range in XML
Start Range in JS
Start End in XML
Start End in JS
Scatter Plot Charts with Date Time Axis
start range in XML
start range in js
start end in XML
start end in js
Also there are three similar methods: setViewXZoom(viewName, settings), setViewYZoom(viewName, settings) and setViewZoom(viewName, settings) for setting zoom in views.
Scroll To Methods
If you'd like to
Get Scroll State Methods
To obtain the state of the scroll bar when needed you can use getXScrollInfo or getYScrollInfo methods. They provide you an access to an object with the following structure:
Field | Value |
---|---|
Start | Number |
Range | Number |
Initiate these method when you need in order to obtain the info:
infoY = chart.getYScrollInfo();
Also there are two similar methods: getViewXScrollInfo(viewName) and getViewYScrollInfo(viewName), that allow to get scroll states from dashboard views.
Scroll State Events
To track the current state of scroll you shoud use XAxisScrollChange and/or YAxisScrollChange events, in these events you can obtain the standart scroll data and phase and process enums, which allow to define the source of scroll:
Field | Possible Values |
---|---|
startValue | Number |
endValue | Number |
range | Number |
phase | start progress process end |
process | plotDrag scrollBar |
Setting event handlers can be attached separately to Y and X axes and should be done like that:
chart.addEventListener("YAxisScrollChange", yAxisChange);
Actions
You can control zoom and scroll using AnyChart Actions. See Actions article for more.