How to Synchronize Trackball Display Across Multiple Vue Charts?
Description
This article demonstrates how to display a trackball (crosshair and tooltip) in multiple Vue charts simultaneously, based on interaction with a single chart.
Solution
Trackballs, or crosshairs, are useful interactive elements that show precise data point values with intersecting vertical and horizontal lines and tooltips. In Vue Charts, you can synchronize trackball tooltips across multiple charts using the following chart events:
- chartMouseMove
- chartMouseLeave
- chartMouseUp
By listening to these events on the primary chart and invoking showCrosshair and hideCrosshair methods on the other charts, you can replicate the trackball behavior across all charts.
Implementation Details
When the user:
- Moves the mouse over the first chart, the chartMouseMove event triggers and calls showCrosshair and showTooltip on the secondary chart.
- Leaves the chart, the chartMouseLeave event hides the tooltip and crosshair.
- Stops dragging, the chartMouseUp event ensures the crosshair/tooltip is hidden.
Code Snippet
chartMouseLeave1: function (args) {
this.$refs.chart2.ej2Instances.hideCrosshair();
this.$refs.chart2.ej2Instances.hideTooltip();
},
chartMouseUp1: function (args) {
if (this.$refs.chart1.ej2Instances.startMove) {
this.$refs.chart2.ej2Instances.hideCrosshair();
this.$refs.chart2.ej2Instances.hideTooltip();
}
},
chartMouseMove1: function (args) {
if ((!this.$refs.chart1.ej2Instances.isTouch && !this.$refs.chart1.ej2Instances.isChartDrag) || this.$refs.chart1.ej2Instances.startMove) {
this.$refs.chart2.ej2Instances.startMove = this.$refs.chart1.ej2Instances.startMove;
this.$refs.chart2.ej2Instances.showTooltip(args.x, args.y);
this.$refs.chart2.ej2Instances.showCrosshair(args.x, args.y);
}
},
Output
The image below shows both charts displaying trackball tooltips in sync:
Live Demo
Conclusion
We hope you enjoyed learning about How to Synchronize Trackball Display Across Multiple Vue Charts.
You can refer to our Vue 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 Vue 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!