How to club data points the React pie charts?
This article explains how to group the React pie data into the “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">
</accumulationseriesdirective></accumulationseriescollectiondirective>
</inject></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">
</accumulationseriesdirective></accumulationseriescollectiondirective>
</inject></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:
Refer to the working sample for additional details and implementation: View Sample in Stackblitz
Conclusion
We hope you enjoyed learning how to group the React pie data into the “Others” category in the React Chart Component.
You can refer to our React Chart feature tour page to learn about its other groundbreaking feature representations and documentation, as well as how to quickly get started with 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, BoldDesk Support, or feedback portal. We are always happy to assist you!