Articles in this section
Category / Section

How to show tooltip when clicking the axis label of React Chart?

This article explains how to display a tooltip when clicking the axis label in a React Chart.

Customize the chart to display a tooltip when clicking the axis label

You can programmatically show the tooltip image by clicking the axis label using the axisLabelClick event and the showTooltip method. Also, set the enable property to true in the tooltip.

You can also utilize the template property to customize the appearance of the tooltip, including showing an image.

In the following code example, the tooltip image is displayed when clicking the axis label.

Index.js

import { createRoot } from 'react-dom/client';
import * as React from 'react';
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, Category,
Tooltip, ColumnSeries } from '@syncfusion/ej2-react-charts';

const Column = () => {
let template =
'<div id="chart_cloud"><img src="https://ej2.syncfusion.com/react/demos/src/chart/images/cloud.png" style="width: 41px; height: 41px"></div>';

const axisLabelClick = (args) => {
  let x = args.chart.series[0].points[args.index].x;
  let y = args.chart.series[0].points[args.index].y;
  args.chart.showTooltip(x, y, true);
};
return (
  <chartcomponent id="charts" legendsettings="{{" enablehighlight:="" true="" }}="" primaryxaxis="{{" valuetype:="" 'category',="" interval:="" 1="" primaryyaxis="{{" maximum:="" 10,="" 2,="" labelformat:="" '{value}°c'="" tooltip="{{" enable:="" true,="" template:="" template="" title="Weather Report" axislabelclick="{axisLabelClick.bind(this)}">
    <inject services="{[ColumnSeries," tooltip,="" category]}="">
    <seriescollectiondirective>
      <seriesdirective datasource="{data}" xname="x" columnspacing="{0.1}" yname="y" type="Column">
    </seriesdirective></seriescollectiondirective>
  </inject></chartcomponent>
);
};
export default Column;

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

The following screenshot portrays the results of the code snippet mentioned above.

Screenshot:

React chart tooltip is shown when clicking an axis label

Refer to the working sample for additional details and implementation: View Sample in Stackblitz

Conclusion

We hope you enjoyed learning how to display a tooltip when clicking the axis label in a 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!

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