How to show tooltip for the clubbed data points in React Pie chart?
This article explains how to display the tooltip with all information for the clubbed data points in the React Pie Chart.
Customize the tooltip for group-to values
You can club/group few points of the series based on the groupTo property.
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 tooltip 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, AccumulationTooltip
} from '@syncfusion/ej2-react-charts';
const Pie = () => {
return (
<AccumulationChartComponent
id="pie-chart"
title="Browser Market Share"
legendSettings={{ visible: true, position: 'Bottom' }}
tooltip={{
enable: true
}}
>
<Inject
services={[ PieSeries, AccumulationDataLabel, AccumulationLegend, AccumulationTooltip ]}
/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective
dataSource={data}
xName="x"
yName="y"
dataLabel={{
visible: true,
name: 'text',
font: { fontWeight: '600' },
connectorStyle: { length: '20px', type: 'Curve' }
}}
radius={Browser.isDevice ? '40%' : '70%'}
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 display the tooltip with the grouped data collection in a React Pie Chart
In the following code example, the tooltip displays information about the data that has been grouped together.
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, AccumulationTooltip } from '@syncfusion/ej2-react-charts';
const Pie = () => {
const tooltipRender = (args) => {
if (args.text.indexOf('Others') != -1) {
args.text = '';
var value = args.series.clubbedPoints.length;
for (var i = 0; i < value; i++) {
args.text = args.text + args.series.clubbedPoints[i].text + (i != value - 1 ? '<br>' : '');
}
}
};
return (
<AccumulationChartComponent
id="pie-chart"
title="Browser Market Share"
legendSettings={{ visible: true, position: 'Bottom' }}
tooltip={{
enable: true
}}
tooltipRender={tooltipRender.bind(this)}
>
<Inject
services={[ PieSeries, AccumulationDataLabel, AccumulationLegend, AccumulationTooltip ]}
/>
<AccumulationSeriesCollectionDirective>
<AccumulationSeriesDirective
dataSource={data}
xName="x"
yName="y"
dataLabel={{
visible: true,
name: 'text',
font: { fontWeight: '600' },
connectorStyle: { length: '20px', type: 'Curve' }
}}
radius={Browser.isDevice ? '40%' : '70%'}
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 show tooltip with all information for the clubbed data points 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!