Labels

The Chart enables you to set the appearance and customize the content of the series and axis labels.

Setting the Appearance

You can control the appearance of the labels through the following properties:

  • background
  • border
  • color
  • font
  • margin
  • padding

The following example demonstrates how to customize the appearance of the axis label by using the ChartValueAxisLabels component.

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

const categories = [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri' ];
const seriesData = [ 20, 40, 45, 30, 50 ];
const valueAxisLabels = {
    padding: 3,
    font: 'bold 16px Arial, sans-serif'
};
const ChartContainer = () => (
    <Chart>
        <ChartCategoryAxis>
            <ChartCategoryAxisItem categories={categories} labels={{ color: '#0a0' }} />
        </ChartCategoryAxis>
        <ChartValueAxis>
            <ChartValueAxisItem labels={valueAxisLabels} />
        </ChartValueAxis>
        <ChartSeries>
            <ChartSeriesItem type="line" data={seriesData} />
        </ChartSeries>
    </Chart>
);

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

The following example demonstrates how to customize the appearance of the series label by using the ChartSeriesLabels component.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {
    Chart,
    ChartSeries,
    ChartSeriesItem
} from '@progress/kendo-react-charts';

const seriesData = [ 20, 40, 45, 30, 50 ];
const seriesLabels = {
    visible: true, // Note that visible defaults to false
    padding: 3,
    font: 'bold 16px Arial, sans-serif'
};

const ChartContainer = () => (
  <Chart>
      <ChartSeries>
          <ChartSeriesItem type="line" data={seriesData} labels={seriesLabels} />
      </ChartSeries>
  </Chart>
);

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

Customizing the Content

Normally, the series and axis Chart labels display an unformatted numeric value or a category name.

You can override the Chart label content by:

Using Format Strings

The Chart enables you to assign a format string for the label. For the full list of available formats, refer to the kendo-intl library.

Formatting Labels as Currency Values

The following example demonstrates how to format the value axis labels as a currency value.

import {
    Chart,
    ChartAxisDefaults,
    ChartSeries,
    ChartSeriesItem
} from '@progress/kendo-react-charts';

const seriesData = [2034, 40124, 45234, 30234, 50234];
const ChartContainer = () => (
    <Chart>
        <ChartAxisDefaults labels={{ format: 'c0' }} />
        <ChartSeries>
            <ChartSeriesItem type="line" data={seriesData} />
        </ChartSeries>
    </Chart>
);

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

The following example demonstrates how to format the series labels as a currency value.

import {
    Chart,
    ChartSeries,
    ChartSeriesItem,
    ChartSeriesLabels
} from '@progress/kendo-react-charts';

const seriesData = [2034, 40124, 45234, 30234, 50234];
const ChartContainer = () => (
    <Chart>
        <ChartSeries>
            <ChartSeriesItem type="line" data={seriesData}>
                <ChartSeriesLabels format="c0" />
            </ChartSeriesItem>
        </ChartSeries>
    </Chart>
);

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

Formatting Placeholders

Format strings for series labels can contain multiple value placeholders—for example, an X and Y value for the Scatter series. The following table lists the available placeholders.

Series TypePlaceholders
Area, Bar, Column, Funnel, Line, and Pie{0}—value
Box Plot
  • {0}—lower
  • {1}—q1
  • {2}—median
  • {3}—q3
  • {4}—upper
  • {5}—mean
  • {6}—category
Bubble
  • {0}—X value
  • {1}—Y value
  • {2}—size value
  • {3}—category name
Bullet
  • {0}—current
  • {1}—target
RangeBar and RangeArea
  • {0}—from
  • {1}—to
Scatter and ScatterLine
  • {0}—X value
  • {1}—Y value
Candlestick and OHLC
  • {0}—open value
  • {1}—high value
  • {2}—low value
  • {3}—close value
  • {4}—category name

The following example demonstrates how to use value placeholders for the Scatter series labels.

import {
    Chart,
    ChartSeries,
    ChartSeriesItem,
    ChartSeriesLabels
} from '@progress/kendo-react-charts';

const weatherData = [
    { windSpeed: 16.4, rainfall: 5.4 },
    { windSpeed: 21.7, rainfall: 2 },
    { windSpeed: 25.4, rainfall: 3 },
    { windSpeed: 19, rainfall: 2 },
    { windSpeed: 10.9, rainfall: 1 },
    { windSpeed: 13.6, rainfall: 3.2 },
    { windSpeed: 10.9, rainfall: 7.4 },
    { windSpeed: 10.9, rainfall: 0 },
    { windSpeed: 10.9, rainfall: 8.2 },
    { windSpeed: 16.4, rainfall: 0 },
    { windSpeed: 16.4, rainfall: 1.8 },
    { windSpeed: 13.6, rainfall: 0.3 },
    { windSpeed: 29.9, rainfall: 0 },
    { windSpeed: 27.1, rainfall: 2.3 },
    { windSpeed: 16.4, rainfall: 0 }
];

const ChartContainer = () => (
  <Chart>
      <ChartSeries>
          <ChartSeriesItem type="scatter" data={weatherData} xField="rainfall" yField="windSpeed">
            <ChartSeriesLabels format="{1:N1} mm; {0:N1} km/h" />
          </ChartSeriesItem>
      </ChartSeries>
  </Chart>
);

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

Setting Content Callbacks

If provided, a content function is called to compute the text of each label. The function receives different parameters depending on the context. For more information, refer to the documentation on ChartCategoryAxisLabelsProps, ChartValueAxisLabelsProps, and ChartSeriesLabelsProps.

The following example demonstrates how to override the content of the axis labels.

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

const seriesData = [20, 40, 45, 30, 50];
const suffix = ' ms';
const labelContent = (e) => (e.value + suffix);

const ChartContainer = () => (
    <Chart>
        <ChartValueAxis>
            <ChartValueAxisItem labels={{ content: labelContent }} />
        </ChartValueAxis>
        <ChartSeries>
            <ChartSeriesItem type="line" data={seriesData} />
        </ChartSeries>
    </Chart>
);

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

The following example demonstrates how to override the content of the series labels.

import {
    Chart,
    ChartSeries,
    ChartSeriesItem,
    ChartSeriesLabels
} from '@progress/kendo-react-charts';

const seriesData = [20, 40, 45, 30, 50];
const suffix = ' ms';
const labelContent = (e) => (e.value + suffix);

const ChartContainer = () => (
    <Chart>
        <ChartSeries>
            <ChartSeriesItem type="line" data={seriesData}>
                <ChartSeriesLabels content={labelContent} />
            </ChartSeriesItem>
        </ChartSeries>
    </Chart>
);

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

Rendering Custom Visuals

You can customize the rendering of labels by using a visual function. The function receives a single parameter of type AxisLabelVisualArgs or SeriesLabelsVisualArgs, and returns a group of Drawing primitives to represent the label.

The following example demonstrates how to override the rendering of the axis labels.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {
    Chart,
    ChartValueAxis,
    ChartValueAxisItem,
    ChartSeries,
    ChartSeriesItem
} from '@progress/kendo-react-charts';
import { Group, Path } from '@progress/kendo-drawing';

const seriesData = [ 2034, 40124, 45234, 30234, 50234 ];

const labelVisual = (e) => {
    const defaultLabel = e.createVisual();

    if (e.value < 40000) {
        return defaultLabel;
    }

    const path = new Path({
        stroke: {
            color: 'red',
            width: 1
        }
    });

    const bbox = defaultLabel.bbox();
    path.moveTo(bbox.bottomLeft()).lineTo(bbox.bottomRight());

    const group = new Group();
    group.append(defaultLabel, path);

    return group;
};

const ChartContainer = () => (
  <Chart>
      <ChartValueAxis>
          <ChartValueAxisItem labels={{ visible: true, visual: labelVisual }} />
      </ChartValueAxis>
      <ChartSeries>
          <ChartSeriesItem type="line" data={seriesData} />
      </ChartSeries>
  </Chart>
);

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

The following example demonstrates how to override the rendering of the series labels.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {
    Chart,
    ChartSeries,
    ChartSeriesItem
} from '@progress/kendo-react-charts';
import { Group, Path } from '@progress/kendo-drawing';

const seriesData = [ 2034, 40124, 45234, 30234, 50234 ];
const labelVisual = (e) => {
    const defaultLabel = e.createVisual();
    const value = parseFloat(e.text);

    if (value < 40000) {
        return defaultLabel;
    }

    const path = new Path({
        stroke: {
            color: 'red',
            width: 1
        }
    });

    const bbox = defaultLabel.bbox();
    path.moveTo(bbox.topLeft()).lineTo(bbox.topRight());

    const group = new Group();
    group.append(defaultLabel, path);

    return group;
};

const ChartContainer = () => (
  <Chart>
      <ChartSeries>
          <ChartSeriesItem
            type="line"
            data={seriesData}
            labels={{ visible: true, visual: labelVisual }}
          />
      </ChartSeries>
  </Chart>
);

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