React PieChart - Customize Labels
If you need to change the text displayed by point labels, declare the customizeText function. It must return a string value. The argument of this function contains information about the point whose label is being customized. In the following example, the customizeText function instructs point labels to display both the argument and value of a point.
- import React from 'react';
- import PieChart, {
- Series,
- Label
- } from 'devextreme-react/pie-chart';
- class App extends React.Component {
- render() {
- return (
- <PieChart ... >
- <Series>
- <Label
- visible={true}
- customizeText={customizeText}
- />
- </Series>
- </PieChart>
- );
- }
- }
- function customizeText({ argument, value }) {
- return `${argument}: ${value}`;
- }
You can also customize an individual label. For this purpose, assign a function to the customizeLabel property. This function must return an object with properties for the label that you want to customize. Note that the customizeLabel property should be declared at the root level of the PieChart configuration.
- import React from 'react';
- import PieChart, {
- Series,
- Label
- } from 'devextreme-react/pie-chart';
- class App extends React.Component {
- render() {
- return (
- <PieChart ...
- customizeLabel={customizeLabel}>
- <Series>
- <Label
- visible={true}
- backgroundColor="blue"
- />
- </Series>
- </PieChart>
- );
- }
- }
- // All point labels with the value more than 100 turn red
- // Other point labels remain blue
- function customizeLabel(pointInfo) {
- return pointInfo.value > 100 ? { backgroundColor: 'red' } : { };
- }
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.