Forum Discussion
Costum Visual Tooltip don't works
Hi Anonymous,
The issue is in the third parameter of your addTooltip method, i.e.:
this.tooltipServiceWrapper.addTooltip(
this.svg.selectAll('rect'),
(tooltipEvent: TooltipEventArgs<number>) => Visual.getTooltipData(tooltipEvent.data),
(tooltipEvent: TooltipEventArgs<number>) => null, <--- THIS PART
true);
This expects an ISelectionId and you are passing null to it, which means that Power BI has no context for the tooltip columns and measures needed to resolve it on your behalf.
You will need to create a selection for the desired data point that the element represents, so that Power BI can resolve it for you and display the correct canvas tooltip.
Provided that the desired column or measure is included in your selection, and the report page tooltip contains one of these then it should then resolve as you expect.
If you want to see an example of this, the MS sampleBarChart has the addTooltip call here, and the selection ID creation as part of mapping the dataset here.
Good luck!
Daniel
Hey Daniel, Whats messed up w/ OPs code is actually how MS has it in their documentation:
https://learn.microsoft.com/en-us/power-bi/developer/visuals/add-tooltips#call-the-addtooltip-method
this.tooltipServiceWrapper.addTooltip(this.barContainer.selectAll('.bar'),
(tooltipEvent: TooltipEventArgs<number>) => BarChart.getTooltipData(tooltipEvent.data),
(tooltipEvent: TooltipEventArgs<number>) => null);
I suspect what MS meant to enter was
this.tooltipServiceWrapper.addTooltip(this.barContainer.selectAll('.bar'),
(tooltipEvent: TooltipEventArgs<number>) => BarChart.getTooltipData(tooltipEvent.data),
null);
Which would would work but only to display static information... The documenation and examples is all over the place and broken for this.