Plot Bands

The Chart plot bands allow you to highlight a specific range of an axis.

To display plot bands, set the axis plotBands option to an array of PlotBand.

The following example demonstrates how to configure the plot bands of an axis.

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

const categoryPlotBands = [{
    from: 1,
    to: 2,
    color: '#ffd246',
    opacity: 0.8
}];

const valuePlotBands = [{
    from: 2,
    to: 3,
    color: '#78d237',
    opacity: 0.8
}];

const ChartContainer = () => (
    <Chart>
        <ChartCategoryAxis>
            <ChartCategoryAxisItem categories={['A', 'B', 'C']} plotBands={categoryPlotBands} />
        </ChartCategoryAxis>
        <ChartValueAxis>
            <ChartValueAxisItem plotBands={valuePlotBands} />
        </ChartValueAxis>
        <ChartSeries>
            <ChartSeriesItem data={[1, 2, 3]} />
        </ChartSeries>
    </Chart>
);

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

Custom Plot Bands

To visualize the range in a different way or to show additional elements, manually draw the plot bands by using the Drawing API in the onRender event.

To get the range coordinates:

  1. Find the axis by name.
  2. Use the slot method.

The following example demonstrates how to draw custom plot bands.

import React from 'react';
import ReactDOM from 'react-dom';

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

class ChartContainer extends React.Component {
    categories = [ 'A', 'B', 'C' ];
    series = [ 1, 2, 3 ];
    plotValue = 3;

    render() {
        return (
            <Chart onRender={this.onRender}>
                <ChartCategoryAxis>
                    <ChartCategoryAxisItem categories={this.categories} name="categoryAxis" />
                </ChartCategoryAxis>
                <ChartValueAxis>
                    <ChartValueAxisItem name="valueAxis" />
                </ChartValueAxis>
                <ChartSeries>
                    <ChartSeriesItem data={this.series} />
                </ChartSeries>
            </Chart>
        );
    }

    onRender = (args) => {
        const chart = args.target.chartInstance;

        if (!chart) return;

        // get the axes
        const valueAxis = chart.findAxisByName("valueAxis");
        const categoryAxis = chart.findAxisByName("categoryAxis");

        // get the coordinates of the value at which the plot band will be rendered
        const valueSlot = valueAxis.slot(this.plotValue);

        // get the coordinates of the entire category axis range
        const range = categoryAxis.range();
        const categorySlot = categoryAxis.slot(range.min, range.max);

        // draw the plot band based on the found coordinates
        const line = new Path({
            stroke: {
                color: "red",
                width: 3
            }
        })
        .moveTo(valueSlot.origin)
        .lineTo(categorySlot.topRight().x, valueSlot.origin.y);

        const label = new Text('MAX', [ 0, 0 ], {
            fill: {
                color: "red"
            },
            font: "14px sans"
        });
        const bbox = label.bbox();
        label.position([ categorySlot.topRight().x - bbox.size.width, valueSlot.origin.y - bbox.size.height ]);

        const group = new Group();
        group.append(line, label);

        //draw on the surface
        chart.surface.draw(group);
    }
}

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