How to display more data in the tooltip of React Chart?
This article explains how to customize and display additional data in the tooltip within the React Chart.
Customize the tooltip to display more data
You can customize the tooltip to display specific information by using the tooltipMappingName property in the series. By default, the tooltip shows information about the x and y values in data points.
In the following code example, the tooltip displays both the country name and population growth details, which are bound to the text field in the data source.
Index.js
import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries,
Category, Tooltip } from '@syncfusion/ej2-react-charts';
export let data = [
{ x: 'US', y: 400, text: 'United States: 400' },
{ x: 'SA', y: 340, text: 'South Africa: 340' },
{ x: 'NL', y: 375, text: 'Netherlands: 375' },
{ x: 'ZIM', y: 430, text: 'Zimbabwe: 430' },
{ x: 'CH', y: 445, text: 'Switzerland: 445' }
];
const Column = () => {
return (
<ChartComponent
id="charts"
primaryXAxis={{
valueType: 'Category',
interval: 1
}}
primaryYAxis={{
minimum: 0,
maximum: 500,
interval: 50
}}
title="Population Growth"
tooltip={{
enable: true,
enableMarker: false,
format: '${point.tooltip}'
}}
>
<Inject services={[ColumnSeries, Category, Tooltip]} />
<SeriesCollectionDirective>
<SeriesDirective
dataSource={data}
xName="x"
yName="y"
type="Column"
fill="#035afc"
tooltipMappingName="text"
/>
</SeriesCollectionDirective>
</ChartComponent>
);
};
export default Column;
const root = createRoot(document.getElementById('sample'));
root.render(<Column />);
The following screenshot illustrate the output of the above code snippet.
Screenshot:
Conclusion
I hope you enjoyed learning how to customize and display additional data in the tooltip within 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!