Panning and Zooming

The Chart enables the user to change the displayed range by panning and zooming.

Panning is performed by dragging over the plot area.

Zooming is performed by either:

  • Mouse-wheeling on desktop or pinch zoom on mobile, or
  • Holding the Shift key and selecting an area.

To enable the pan-and-zoom functionality, use the pannable and zoomable options.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import 'hammerjs';

import {
    Chart,
    ChartSeries,
    ChartSeriesItem,
    ChartValueAxis,
    ChartValueAxisItem,
    ChartCategoryAxis,
    ChartCategoryAxisItem
} from '@progress/kendo-react-charts';

const generateSeries = () => {
    const series = [];

    for (let idx = 0; idx < 10000; idx++) {
        series.push({
            value: Math.floor(Math.random() * 100) + 1,
            category: new Date(2000, 0, idx)
        });
    }

    return series;
};

class ChartContainer extends React.Component {
    state = {
        series: generateSeries(),
        categoryAxisMax: new Date(2000, 1, 0),
        categoryAxisMaxDivisions: 10
    }

    render() {
        const { series, categoryAxisMax, categoryAxisMaxDivisions } = this.state;

        return (
            <Chart pannable={true} zoomable={true}>
                <ChartCategoryAxis>
                    <ChartCategoryAxisItem max={categoryAxisMax} maxDivisions={categoryAxisMaxDivisions} />
                </ChartCategoryAxis>
                <ChartValueAxis>
                    <ChartValueAxisItem labels={{ visible: true, format: '#.00' }} />
                </ChartValueAxis>
                <ChartSeries>
                    <ChartSeriesItem data={series} field="value" categoryField="category" />
                </ChartSeries>
            </Chart>
        );
    }
}

ReactDOM.render(
    <ChartContainer />,
    document.querySelector('my-app')
);

Disabling Pan-and-Zoom Direction

You can prevent panning and zooming for an axis by using the lock configuration. To disable pan-and-zoom in the vertical direction, set the pannable.lock, zoomable.mouoswheel.lock, and zoomable.selection.lock options to 'y'. To disable pan-and-zoom in the horizontal direction, set the pannable.lock, zoomable.mouoswheel.lock, and zoomable.selection.lock options to 'x'.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import 'hammerjs';

import {
    Chart,
    ChartSeries,
    ChartSeriesItem,
    ChartValueAxis,
    ChartValueAxisItem,
    ChartCategoryAxis,
    ChartCategoryAxisItem
} from '@progress/kendo-react-charts';

const generateSeries = () => {
    const series = [];

    for (let idx = 0; idx < 10000; idx++) {
        series.push({
            value: Math.floor(Math.random() * 100) + 1,
            category: new Date(2000, 0, idx)
        });
    }

    return series;
};

class ChartContainer extends React.Component {
    state = {
        series: generateSeries(),
        categoryAxisMax: new Date(2000, 1, 0),
        categoryAxisMaxDivisions: 10
    }

    render() {
        const { series, categoryAxisMax, categoryAxisMaxDivisions } = this.state;

        return (
            <Chart pannable={{ lock: 'y' }} zoomable={{ mousewheel: { lock: 'y' }, selection: { lock: 'y' } }}>
                <ChartCategoryAxis>
                    <ChartCategoryAxisItem max={categoryAxisMax} maxDivisions={categoryAxisMaxDivisions} />
                </ChartCategoryAxis>
                <ChartValueAxis>
                    <ChartValueAxisItem labels={{ visible: true, format: '#.00' }} />
                </ChartValueAxis>
                <ChartSeries>
                    <ChartSeriesItem data={series} field="value" categoryField="category" />
                </ChartSeries>
            </Chart>
        );
    }
}

ReactDOM.render(
    <ChartContainer />,
    document.querySelector('my-app')
);
 /