Zooming in React Chart component
28 Mar 202524 minutes to read
To get start quickly with React Chart Zooming and Panning, you can check on this video:
Enable zooming
Chart can be zoomed in three ways.
- Selection - By setting
enableSelectionZooming
property to true inzoomSettings, you can zoom the chart by using the rubber band selection. - Mousewheel - By setting
enableMouseWheelZoomingproperty to true inzoomSettings, you can zoomin and zoomout the chart by scrolling the mouse wheel. - Pinch - By setting
enablePinchZoomingproperty to true inzoomSettings, 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 { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const legendSettings = { visible: false };
const zoomsettings = {
enableMouseWheelZooming: true, enablePinchZooming: true,
enableSelectionZooming: true
};
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} legendSettings={legendSettings} zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const legendSettings: LegendSettingsModel = { visible: false };
const zoomsettings: ZoomSettingsModel = {
enableMouseWheelZooming: true, enablePinchZooming: true,
enableSelectionZooming: true
};
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let zoomData = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];export let zoomData: Object[] = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];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.
Modes
The mode property in zoomSettings specifies whether the chart 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.
- X - Allows us to zoom the chart horizontally.
- Y - Allows us to zoom the chart vertically.
- XY - Allows us to zoom the chart both vertically and horizontally.
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';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const legendSettings = { visible: false };
const zoomsettings = { mode: 'X', enableSelectionZooming: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} legendSettings={legendSettings} zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const legendSettings: LegendSettingsModel = { visible: false };
const zoomsettings: ZoomSettingsModel = { mode: 'X', enableSelectionZooming: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let zoomData = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];export let zoomData: Object[] = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];Toolbar
By default, zoomin, zoomout, pan and reset buttons will be displayed for zoomed chart. You can customize to show the desired options in the toolbar using the toolbarItems property. Also using the showToolbar property, you can show toolkit for zooming and panning the chart during initial rendering itself.
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';
function App() {
const primaryxAxis = { valueType: 'DateTime' };
const legendSettings = { visible: false };
const zoomsettings = { enableSelectionZooming: true, toolbarItems: ['Zoom', 'Pan', 'Reset'], showToolbar: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} legendSettings={legendSettings} zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime' };
const legendSettings: LegendSettingsModel = { visible: false };
const zoomsettings: ZoomSettingsModel = { enableSelectionZooming: true, toolbarItems: ['Zoom', 'Pan', 'Reset'], showToolbar: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let zoomData = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];export let zoomData: Object[] = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];Toolbar customization
The zoom toolbar in the chart can be repositioned using the toolbarPosition property, allowing flexible alignment and placement. It supports horizontal alignments (Near, Center, and Far) and vertical alignments (Top, Middle, and Bottom), with default values set to Far and Top, respectively. For precise placement, the x and y properties can be used to adjust the toolbar’s position within the chart area. Additionally, enabling the draggable property allows users to freely move the toolbar within the chart area, ensuring optimal usability.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, AreaSeries, Zoom } from'@syncfusion/ej2-react-charts';
import { series1 } from './datasource';
function App() {
const primaryxAxis = {
title: 'Years',
valueType: 'DateTime',
labelFormat: 'yMMM',
edgeLabelPlacement: 'Shift',
majorGridLines : { width : 0 }
};
const primaryyAxis = {
title: 'Profit ($)',
rangePadding: 'None',
lineStyle : { width: 0 },
majorTickLines : {width : 0}
};
const legendSettings = { visible: false };
const zoomsettings = {
enableSelectionZooming: true,
toolbarItems: ['Zoom', 'Pan', 'Reset'],
showToolbar: true,
toolbarPosition: {
y: -10,
draggable: true,
horizontalAlignment: "Far",
verticalAlignment: "Top"
}
};
const chartarea = { border: { width: 0 } };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
legendSettings={legendSettings}
zoomSettings={zoomsettings}
chartArea={chartarea}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={series1} xName='x' yName='y' name='Product X' opacity={0.3} type='Area' border={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, AxisModel, LegendSettingsModel, ZoomSettingsModel, ChartAreaModel, Legend, DateTime, AreaSeries, Zoom } from'@syncfusion/ej2-react-charts';
import { series1 } from './datasource';
function App() {
const primaryxAxis: AxisModel = {
title: 'Years',
valueType: 'DateTime',
labelFormat: 'yMMM',
edgeLabelPlacement: 'Shift',
majorGridLines : { width : 0 }
};
const primaryyAxis: AxisModel = {
title: 'Profit ($)',
rangePadding: 'None',
lineStyle : { width: 0 },
majorTickLines : {width : 0}
};
const legendSettings: LegendSettingsModel = { visible: false };
const zoomsettings: ZoomSettingsModel = {
enableSelectionZooming: true,
toolbarItems: ['Zoom', 'Pan', 'Reset'],
showToolbar: true,
toolbarPosition: {
y: -10,
draggable: true,
horizontalAlignment: "Far",
verticalAlignment: "Top"
}
};
const chartarea: ChartAreaModel = { border: { width: 0 } };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
legendSettings={legendSettings}
zoomSettings={zoomsettings}
chartArea={chartarea}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={series1} xName='x' yName='y' name='Product X' opacity={0.3} type='Area' border={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let series1 = [];
let point1;
let value = 40;
let i;
for (i = 1; i < 500; i++) {
if (Math.random() > .5) {
value += Math.random();
} else {
value -= Math.random();
}
point1 = { x: new Date(1950, i + 2, i), y: value.toFixed(1) };
series1.push(point1);
}export let series1: Object[] = [];
let point1: Object;
let value: number = 40;
let i: number;
for (i = 1; i < 500; i++) {
if (Math.random() > .5) {
value += Math.random();
} else {
value -= Math.random();
}
point1 = { x: new Date(1950, i + 2, i), y: value.toFixed(1) };
series1.push(point1);
}Enable scrollbar
Using the enableScrollbar property, you can add a scrollbar to a zoomed chart. This scrollbar allows you to zoom or pan the chart. The appearance of the scrollbar can be customized using properties in scrollbarSettings. For example, you can use trackColor and trackRadius properties to customize the track of the scrollbar, and scrollbarRadius and scrollbarColor properties to customize the scroller. The ability to zoom through the scrollbar can be enabled or disabled using the enableZoom property in scrollbarSettings. Additionally, you can change the color of the grip and height of the scrollbar using the gripColor and height properties.
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';
function App() {
const primaryxAxis = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6, scrollbarSettings: { enable: true, enableZoom: false, height: 14, trackRadius: 8, scrollbarRadius: 8, gripColor: 'transparent', trackColor: 'yellow', scrollbarColor: 'red' } };
const legendSettings = { visible: false };
const zoomsettings = { enableSelectionZooming: true, enableScrollbar: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} legendSettings={legendSettings} zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6, scrollbarSettings: { enable: true, enableZoom: false, height: 14, trackRadius: 8, scrollbarRadius: 8, gripColor: 'transparent', trackColor: 'yellow', scrollbarColor: 'red' } };
const legendSettings: LegendSettingsModel = { visible: false };
const zoomsettings: ZoomSettingsModel = { enableSelectionZooming: true, enableScrollbar: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let zoomData = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];export let zoomData: Object[] = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];Position
The position property allows users to specify their preferred scrollbar location. By default, both vertical and horizontal scrollbars are rendered near their respective axes. Using the customization options below, you can position the scrollbar as desired:
- Default:
placeNextToAxisLine. - Horizontal scrollbar: Available positions are
TopandBottom. - Vertical scrollbar: Available positions are
LeftandRight.
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';
function App() {
const primaryxAxis = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6,
scrollbarSettings: {
enable: true,
enableZoom: false,
height: 14,
trackRadius: 8,
scrollbarRadius: 8,
gripColor: 'transparent',
trackColor: 'yellow',
scrollbarColor: 'red',
position:'Bottom',
}};
const primaryYAxis = {
scrollbarSettings: {
enable: true,
enableZoom: false,
height: 14,
trackRadius: 8,
scrollbarRadius: 8,
gripColor: 'transparent',
trackColor: 'yellow',
scrollbarColor: 'red',
position:'Right',
}
}
const legendSettings = { visible: false };
const zoomsettings = { enableSelectionZooming: true, enableScrollbar: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis = {primaryYAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6,
scrollbarSettings: {
enable: true,
enableZoom: false,
height: 14,
trackRadius: 8,
scrollbarRadius: 8,
gripColor: 'transparent',
trackColor: 'yellow',
scrollbarColor: 'red',
position:'Bottom',
}};
const primaryYAxis: AxisModel = {
scrollbarSettings: {
enable: true,
enableZoom: false,
height: 14,
trackRadius: 8,
scrollbarRadius: 8,
gripColor: 'transparent',
trackColor: 'yellow',
scrollbarColor: 'red',
position:'Right',
}
}
const legendSettings: LegendSettingsModel = { visible: false };
const zoomsettings: ZoomSettingsModel = { enableSelectionZooming: true, enableScrollbar: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis = {primaryYAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let zoomData = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];export let zoomData: Object[] = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];Enable animation
Use the enableAnimation property to create smooth transitions when zooming in on 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}
from'@syncfusion/ej2-react-charts';
import { series1 } from "../datasource";
function App() {
const primaryxAxis = { valueType: 'DateTime',
labelFormat: 'yMMM',
zoomFactor: 0.2, zoomPosition: 0.6,
};
const legendSettings = { visible: false };
const zoomSettings = { enableSelectionZooming: true, enableAnimation: true ,
enablePan: true };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={zoomSettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={series1} type='Area' xName='x' yName='y' name='Product X' opacity={0.3} >
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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 { series1 } from "../datasource";
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime',
labelFormat: 'yMMM',
zoomFactor: 0.2, zoomPosition: 0.6,
};
const legendSettings: LegendSettingsModel = { visible: false };
const zoomSettings: ZoomSettingsModel = { enableSelectionZooming: true, enableAnimation: true ,
enablePan: true };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={zoomSettings}
title='Sales History of Product X'>
<Inject services={[AreaSeries, Legend, Tooltip, DataLabel, Zoom, DateTime]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={series1} type='Area' xName='x' yName='y' name='Product X' opacity={0.3} >
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));Enable pan
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 { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6 };
const legendSettings = { visible: false };
const zoomSettings = { enableSelectionZooming: true, enablePan: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} legendSettings={legendSettings} zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime', zoomFactor: 0.2, zoomPosition: 0.6 };
const legendSettings: LegendSettingsModel = { visible: false };
const zoomSettings: ZoomSettingsModel = { enableSelectionZooming: true, enablePan: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let zoomData: Object[] = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];Auto interval on zooming
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 { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Legend, DateTime, Tooltip, DataLabel, AreaSeries, Zoom } from '@syncfusion/ej2-react-charts';
import { zoomData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'DateTime', enableAutoIntervalOnZooming: true };
const legendSettings = { visible: false };
const zoomSettings = { enableSelectionZooming: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} legendSettings={legendSettings} zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));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';
function App() {
const primaryxAxis: AxisModel = { valueType: 'DateTime', enableAutoIntervalOnZooming: true };
const legendSettings: LegendSettingsModel = { visible: false };
const zoomSettings: ZoomSettingsModel = { enableSelectionZooming: true };
const border = { width: 0.5, color: '#00bdae' };
const animation = { enable: false };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
legendSettings={legendSettings}
zoomSettings={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={border} animation={animation}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));export let zoomData = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];export let zoomData: Object[] = [
{ x: new Date(2016, 0, 1), y: 7.1 },
{ x: new Date(2016, 1, 1), y: 3.7 },
{ x: new Date(2016, 2, 1), y: 0.8 },
{ x: new Date(2016, 3, 1), y: 6.3 },
{ x: new Date(2016, 4, 1), y: 13.3 },
{ x: new Date(2016, 5, 1), y: 18.0 },
{ x: new Date(2016, 6, 1), y: 19.8 },
{ x: new Date(2016, 7, 1), y: 18.1 },
{ x: new Date(2016, 8, 1), y: 13.1 },
{ x: new Date(2016, 9, 1), y: 4.1 },
{ x: new Date(2016, 10, 1), y: -3.8 },
{ x: new Date(2016, 11, 1), y: -6.8 }
];Note: To use zooming feature, we need to inject
Zoommodule into theservices.