Articles in this section
Category / Section

How to display other information in React Chart data label?

3 mins read

This article explains how to display other information in the data label in the React Chart.

Customize the display of additional information in the data label

You can easily display additional information along with the data label by using the name property. By default, the data label shows the y value in the datasource.

In the following code example, the data label is displayed with additional information on the x value using the name property.

Index.js

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { Browser } from '@syncfusion/ej2-base';
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective,
 Inject, AccumulationLegend, PieSeries, AccumulationDataLabel } from '@syncfusion/ej2-react-charts';
 
export let data = [
  { x: 'David', y: 180, text: 'David: 180' },
  { x: 'Micheal', y: 170, text: 'Micheal: 170' },
  { x: 'Steve', y: 160, text: 'Steve: 160' },
  { x: 'Joel', y: 182, text: 'Joel: 182' }
];

const Pie = () => {
 return (
       <AccumulationChartComponent
         id="pie-chart"
         legendSettings={{ visible: true, position: 'Bottom' }}
       >
         <Inject
           services={[AccumulationLegend, PieSeries, AccumulationDataLabel]}
         />
         <AccumulationSeriesCollectionDirective>
           <AccumulationSeriesDirective
             dataSource={data}
             xName="x"
             yName="y"
             startAngle={Browser.isDevice ? 55 : 90}
             dataLabel={{
               visible: true,
               position: 'Inside',
               name: 'text',
               font: { fontWeight: '600', color: '#ffffff' },
               connectorStyle: { length: '20px', type: 'Curve' }
             }}
             radius={Browser.isDevice ? '40%' : '80%'}
             legendShape="Circle"
           />
         </AccumulationSeriesCollectionDirective>
       </AccumulationChartComponent>
   );
};
export default Pie;

const root = createRoot(document.getElementById('sample'));
root.render(<Pie />);

The following screenshot illustrate the output of the above code snippet.

Screenshot:

React chart data label

View Sample in Stackblitz

Conclusion

I hope you enjoyed learning how to display other information in the data label in the React Chart Component.

You can refer to our React Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Chart example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied