How to show the tooltip for annotation in Angular Charts?
Description
This article shows how to display a tooltip for the annotation in Angular Charts using the chartMouseLeave event.
Solution
The annotation is used to add explanatory text or graphical elements to a chart to provide additional information or context. The tooltip can be shown while hovering over an annotation by using the chartMouseLeave event in the chart.
The mouseMove event should be bound to the div element that contains the content of the annotation. While hovering over the annotation, this event is triggered to show the tooltip in the appropriate position relative to the annotation.
Code Snippet
In the following example, the process above described is carried out using the mouseMove and chartMouseLeave methods. The following example shows how to render the tooltip for the annotation.
app.component.ts
public mouseMove(args): void {
this.annotationEle = document.getElementById('container_Annotation_0');
this.tooltipEle = document.getElementsByClassName("tooltip")[0];
this.tooltipEle.style.display = "block";
this.tooltipEle.style.left = parseFloat(this.annotationEle.style.left.split('px')[0]) + 35 + "px";
this.tooltipEle.style.top = this.annotationEle.style.top;
this.tooltipEle.innerHTML = "Custom Text";
}
public chartMouseLeave(args: IMouseEventArgs): void {
if(this.tooltipEle !=null)
this.tooltipEle.style.display = "none";
}
};
The following screenshot illustrates the output of the above code snippet:
Refer to the working sample for additional details and implementation:View Sample in Stackblitz
Conclusion
We hope you enjoyed learning how to show the tooltip for annotation in Angular Chart.
You can refer to our Angular Charts feature tour page to learn about its other features and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular Charts example to understand how to create and visualize 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 comment section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!