JavaScript/jQuery PieChart - Handle Tooltip Events
When a tooltip becomes shown or hidden, the PieChart fires the tooltipShown or tooltipHidden event that you can handle with a function. If the handling function is not going to be changed during the lifetime of the UI component, assign it to the onTooltipShown or onTooltipHidden property respectively, when you configure the UI component.
jQuery
$(function() { $("#pieChartContainer").dxPieChart({ // ... onTooltipShown: function (e) { var point = e.target; // Handler of the "tooltipShown" event }, onTooltipHidden: function (e) { var point = e.target; // Handler of the "tooltipHidden" event } }); });
Angular
<dx-pie-chart ... (onTooltipShown)="onTooltipShown($event)" (onTooltipHidden)="onTooltipHidden($event)"> </dx-pie-chart>
import { DxPieChartModule } from "devextreme-angular"; // ... export class AppComponent { onTooltipShown (e) { let point = e.target; // Handler of the "tooltipShown" event }, onTooltipHidden (e) { let point = e.target; // Handler of the "tooltipHidden" event } } @NgModule({ imports: [ // ... DxPieChartModule ], // ... })
Vue
<template> <DxPieChart ... @tooltip-shown="onTooltipShown" @tooltip-hidden="onTooltipHidden"> </DxPieChart> </template> <script> import DxPieChart from 'devextreme-vue/pie-chart'; export default { components: { DxPieChart }, methods: { onTooltipShown(e) { let point = e.target; // Handler of the "tooltipShown" event }, onTooltipHidden(e) { let point = e.target; // Handler of the "tooltipHidden" event } } } </script>
React
import React from 'react'; import PieChart from 'devextreme-react/pie-chart'; class App extends React.Component { render() { return ( <PieChart ... onTooltipShown={onTooltipShown} onTooltipHidden={onTooltipHidden}> </PieChart> ); } } function onTooltipShown(e) { let point = e.target; // Handler of the "tooltipShown" event } function onTooltipHidden(e) { let point = e.target; // Handler of the "tooltipHidden" event }
If you are going to change the event handlers at runtime or if you need to attach several handlers to a single event, subscribe to this event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.
var tooltipShownHandler1 = function (e) { var point = e.target; // First handler of the "tooltipShown" event }; var tooltipShownHandler2 = function (e) { var point = e.target; // Second handler of the "tooltipShown" event }; $("#pieChartContainer").dxPieChart("instance") .on("tooltipShown", tooltipShownHandler1) .on("tooltipShown", tooltipShownHandler2);
See Also
- Handle Events: Angular | Vue | React | jQuery | AngularJS | Knockout | ASP.NET MVC 5 | ASP.NET Core
If you have technical questions, please create a support ticket in the DevExpress Support Center.