Chart can be zoomed in three ways.
enableSelectionZooming
property to true in zoomSettings
, you can zoom the chart by using the rubber band selection.enableMouseWheelZooming
property to true
in zoomSettings
, you can zoomin and zoomout the chart by scrolling the mouse wheel.enablePinchZooming
property to true in zoomSettings
, you can zoom the chart through pinch gesture in touch enabled devices.Note: Pinch zooming is supported only in browsers that support multi-touch gestures. Currently IE11, Chrome and Opera browsers support multi-touch in desktop devices.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,ZoomSettingsModel,
Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom}
from'@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = { valueType: 'DateTime' };
public legendSettings: LegendSettingsModel = { visible: false };
public zoomsettings: ZoomSettingsModel = {
enableMouseWheelZooming: true, enablePinchZooming: true,
enableSelectionZooming: true
};
public border = { width: 0.5, color: '#00bdae' };
public animation = { enable: false };
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}
legendSettings={this.legendSettings}
zoomSettings={this.zoomsettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' opacity={0.3} name='Product X' type='Area'
border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component {
constructor() {
super(...arguments);
this.primaryxAxis = { valueType: 'DateTime' };
this.legendSettings = { visible: false };
this.zoomsettings = {
enableMouseWheelZooming: true, enablePinchZooming: true,
enableSelectionZooming: true
};
this.border = { width: 0.5, color: '#00bdae' };
this.animation = { enable: false };
}
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis} legendSettings={this.legendSettings} zoomSettings={this.zoomsettings} title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' opacity={0.3} name='Product X' type='Area' border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
}
;
ReactDOM.render(<App />, document.getElementById("charts"));
After zooming the chart, a zooming toolbar will appear with zoom
,zoomin
, zoomout
, pan
and reset
buttons.
Selecting the Pan option will allow to pan the chart and selecting the Reset option will reset the zoomed chart.
The mode
property in zoomSettings specifies whether the c
hart is allowed to scale along the horizontal axis or vertical axis. The default value of the mode is XY (both axis).
There are three types of mode.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,ZoomSettingsModel,
Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom}
from'@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = { valueType: 'DateTime' };
public legendSettings: LegendSettingsModel = { visible: false };
public zoomsettings: ZoomSettingsModel = { mode: 'X', enableSelectionZooming: true };
public border = { width: 0.5, color: '#00bdae' };
public animation = { enable: false };
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}
legendSettings={this.legendSettings}
zoomSettings={this.zoomsettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' opacity={0.3} name='Product X' type='Area'
border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component {
constructor() {
super(...arguments);
this.primaryxAxis = { valueType: 'DateTime' };
this.legendSettings = { visible: false };
this.zoomsettings = { mode: 'X', enableSelectionZooming: true };
this.border = { width: 0.5, color: '#00bdae' };
this.animation = { enable: false };
}
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis} legendSettings={this.legendSettings} zoomSettings={this.zoomsettings} title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' opacity={0.3} name='Product X' type='Area' border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
}
;
ReactDOM.render(<App />, document.getElementById("charts"));
By default, zoomin, zoomout, pan and reset buttons will be displayed for zoomed chart.
You can customize to show your desire tools in the toolbar using
toolbarItems
property.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,ZoomSettingsModel,
Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom}
from'@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = { valueType: 'DateTime' };
public legendSettings: LegendSettingsModel = { visible: false };
public zoomsettings: ZoomSettingsModel = { enableSelectionZooming: true, toolbarItems: ['Zoom', 'Pan', 'Reset'] };
public border = { width: 0.5, color: '#00bdae' };
public animation = { enable: false };
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}
legendSettings={this.legendSettings}
zoomSettings={this.zoomsettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area'
border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component {
constructor() {
super(...arguments);
this.primaryxAxis = { valueType: 'DateTime' };
this.legendSettings = { visible: false };
this.zoomsettings = { enableSelectionZooming: true, toolbarItems: ['Zoom', 'Pan', 'Reset'] };
this.border = { width: 0.5, color: '#00bdae' };
this.animation = { enable: false };
}
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis} legendSettings={this.legendSettings} zoomSettings={this.zoomsettings} title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area' border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
}
;
ReactDOM.render(<App />, document.getElementById("charts"));
Using enableScrollbar
property, you can able to add scrollbar for zoomed chart.
Using this scrollbar, you can pan or zoom the chart.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,ZoomSettingsModel,
Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom, ScrollBar }
from'@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6 };
public legendSettings: LegendSettingsModel = { visible: false };
public zoomsettings: ZoomSettingsModel = { enableSelectionZooming: true, enableScrollbar: true };
public border = { width: 0.5, color: '#00bdae' };
public animation = { enable: false };
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}
legendSettings={this.legendSettings}
zoomSettings={this.zoomsettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime, ScrollBar]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area'
border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom, ScrollBar } from '@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component {
constructor() {
super(...arguments);
this.primaryxAxis = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6 };
this.legendSettings = { visible: false };
this.zoomsettings = { enableSelectionZooming: true, enableScrollbar: true };
this.border = { width: 0.5, color: '#00bdae' };
this.animation = { enable: false };
}
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis} legendSettings={this.legendSettings} zoomSettings={this.zoomsettings} title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime, ScrollBar]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area' border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
}
;
ReactDOM.render(<App />, document.getElementById("charts"));
Using enablePan
property you can able to
pan the zoomed chart without help of toolbar items.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,ZoomSettingsModel,
Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom}
from'@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6 };
public legendSettings: LegendSettingsModel = { visible: false };
public zoomSettings: ZoomSettingsModel = { enableSelectionZooming: true, enablePan: true };
public border = { width: 0.5, color: '#00bdae' };
public animation = { enable: false };
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}
legendSettings={this.legendSettings}
zoomSettings={this.zoomSettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area'
border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component {
constructor() {
super(...arguments);
this.primaryxAxis = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6 };
this.legendSettings = { visible: false };
this.zoomSettings = { enableSelectionZooming: true, enablePan: true };
this.border = { width: 0.5, color: '#00bdae' };
this.animation = { enable: false };
}
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis} legendSettings={this.legendSettings} zoomSettings={this.zoomSettings} title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area' border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
}
;
ReactDOM.render(<App />, document.getElementById("charts"));
By using enableAutoIntervalOnZooming
property,
the axis interval will get calculated automatically with respect to the zoomed range.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject,LegendSettingsModel,ZoomSettingsModel,
Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom}
from'@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = { valueType: 'DateTime', enableAutoIntervalOnZooming: true };
public legendSettings: LegendSettingsModel = { visible: false };
public zoomSettings: ZoomSettingsModel = { enableSelectionZooming: true };
public border = { width: 0.5, color: '#00bdae' };
public animation = { enable: false };
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}
legendSettings={this.legendSettings}
zoomSettings={this.zoomSettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area'
border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from 'datasource.ts';
class App extends React.Component {
constructor() {
super(...arguments);
this.primaryxAxis = { valueType: 'DateTime', enableAutoIntervalOnZooming: true };
this.legendSettings = { visible: false };
this.zoomSettings = { enableSelectionZooming: true };
this.border = { width: 0.5, color: '#00bdae' };
this.animation = { enable: false };
}
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis} legendSettings={this.legendSettings} zoomSettings={this.zoomSettings} title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={zoomData} xName='x' yName='y' name='Product X' opacity={0.3} type='Area' border={this.border} animation={this.animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
}
;
ReactDOM.render(<App />, document.getElementById("charts"));
Note: To use zooming feature, we need to inject Zoom
module into the services
.