How to club data points the React pie charts?
This article explains how to club the React pie data to “Others” category in the React Pie Chart.
How to display the sum of values that are grouped in a React Pie Chart
In the following code example, if the club value is set to 7, points with values less than 7 are grouped together and displayed as a single point with the label Others.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { Browser } from '@syncfusion/ej2-base';
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective,
Inject, PieSeries, AccumulationDataLabel, AccumulationLegend } from '@syncfusion/ej2-react-charts';
const Pie = () => {
return (
<AccumulationChartComponent
id="pie-chart"
title="Browser Market Share"
legendSettings={{ visible: true, position: 'Bottom' }}
>
<Inject
services={[PieSeries, AccumulationDataLabel, AccumulationLegend]}
/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective
dataSource={data}
xName="x"
yName="y"
explode={true}
explodeOffset="10%"
dataLabel={{
visible: true
}}
groupTo="7"
legendShape="Circle"
/>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
);
};
export default Pie;
const root = createRoot(document.getElementById('sample'));
root.render(<Pie />);
The following screenshot portrays the results of the code snippet mentioned above.
Screenshot:
How to bind the data labels to the grouped data collection in a React Pie Chart
In the following code example, if the club value is set to 7, points with values less than 7 are grouped together and will display the values present inside the Others group.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { Browser } from '@syncfusion/ej2-base';
import { AccumulationChartComponent, AccumulationSeriesCollectionDirective, AccumulationSeriesDirective,
Inject, PieSeries, AccumulationDataLabel, AccumulationLegend } from '@syncfusion/ej2-react-charts';
const Pie = () => {
const textRender = (args) => {
if (args.text.indexOf('Others') != -1) {
args.text = '';
for (var i = 0; i < args.series.clubbedPoints.length; i++) {
args.text = args.text + '<br>' + args.series.clubbedPoints[i].text;
}
}
};
return (
<AccumulationChartComponent
id="pie-chart"
title="Browser Market Share"
legendSettings={{ visible: true, position: 'Bottom' }}
textRender={textRender.bind(this)}
>
<Inject
services={[PieSeries, AccumulationDataLabel, AccumulationLegend]}
/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective
dataSource={data}
xName="x"
yName="y"
explode={true}
explodeOffset="10%"
startAngle={Browser.isDevice ? 55 : 35}
dataLabel={{
visible: true,
position: 'Outside',
name: 'text',
font: { fontWeight: '600' },
connectorStyle: { length: '20px', type: 'Curve' }
}}
radius={Browser.isDevice ? '40%' : '50%'}
groupTo="7"
legendShape="Circle"
/>
</AccumulationSeriesCollectionDirective>
</AccumulationChartComponent>
);
};
export default Pie;
const root = createRoot(document.getElementById('sample'));
root.render(<Pie />);
The following screenshot portrays the results of the code snippet mentioned above.
Screenshot:
Conclusion
I hope you enjoyed learning how to club the React pie data to “Others” category 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!