Hi
I want to customize the hover tool tip which is displaying during data point hover. Below is the sample
Can you please help on this.
Thanks
Nithya
Hi
I want to customize the hover tool tip which is displaying during data point hover. Below is the sample
Can you please help on this.
Thanks
Nithya
In order to have a fully-custom tooltip like the one above, youâll need to add a handler for the plotly_hover
event where you would add a custom <div>
to DOM and position it using the event data.
Some useful info: https://plot.ly/javascript/hover-events/
but is there position info in the event data?
As in x
/ y
data position or pixel position?
If the former, see Documentation on Plotly hover and click events - #2 by etienne for more info
If the latter, then see: https://codepen.io/etpinard/pen/wGEjMB
Hi @etienne,
Iâm trying to customize the tool tip for a box and whisker chart .
Looks like if the x-axis value is not an integer, in my case the x-axis ticks are time ranges (10:45 - 11:00) then i get an undefined as pixel value.
Do you have any recommendation that i can use to customize the tool tip for a box and whisker? I would like create a custom tooltip that will show min,max,quartile,median and some additional values in the tooltip.
Thanks in advance.
Can you share a code snippet of what you attempted so far? This will help understand what exactly youâre trying to do. Thanks.
Here is the link to the sample : https://jsfiddle.net/sjselvan/3q42oxhh/?utm_source=website&utm_medium=embed&utm_campaign=3q42oxhh
It looks like the x pixel position is always undefined and it has nothing to do with the x-axis ticks.
All Iâm trying to do is to replace the default tool tip with a custom tooltip for the box & whisker which will show [Max: 5 , Upper Quartile: 3, Median : 3, Lower Quartile : 3, Min : 2, Time : 10:45 - 11:00, Random_Property:Value].
Hereâs how to get the boxes corresponding calc data on hover (which is essentially the set of datum we use to draw things internally) â Edit fiddle - JSFiddle - Code Playground
You might want to look at Boxplot hoverinfo text not display
Thanks @etienne. Iâm able to add a text using annotations. Iâll post the complete solution soon.
@etienne Is there a way to
See Edit fiddle - JSFiddle - Code Playground
You might want to try xanchor
and yanchor
to fine-tuned the positioning of your annotations.
Hi @etienne,
Iâve a similar use case like @nithyaranim, but this time within a heatmap.
Iâm using the l2p (whatâs this acronym standing for?) in combination with the pointNumber data to get a relative positioning within the heatmap. It looks like:
x: point.xaxis.l2p(point.pointNumber[1]),
y: point.yaxis.l2p(point.pointNumber[0])
But the problem with that is that it is relative to the top/left origin of the heatmap svg itself without the outer x- and y-axis labels, so Iâm actually missing that part and wonder about whether there isnât a built-in functionality to get this positioning information directly? The problem is that using external divs as tooltip area that they are located completely outside of the chart and with that I need the information with reference to the top/left origin outside of the chart and the axis labeling.
What seems to work is to use the axis private _offset property and add it to the x and y positions above, so I get
x: point.xaxis.l2p(point.pointNumber[1]) + point.xaxis._offset,
y: point.yaxis.l2p(point.pointNumber[0]) + point.yaxis._offset
But that looks quite nasty to me. Can you point me to some documentation or demo on how to do that âthe plotly wayâ esp. for the heatmap?
Thx in advance,
Andreas
That stands for linear-to-pixel.
Unfortunately, thatâs properly the best we have available at the moment.
Weâre hoping to clean up our event data in v2. See wishlist for potential breaking changes since v1 ¡ Issue #420 ¡ plotly/plotly.js ¡ GitHub for more info.
Hi etienne,
ok. Thx nevertheless. I will then look forward for the v2 release.
Hi @andi1984, thanks for your solution to this, Itâs very helpful to me.
@etienne Iâm working off of this example, but what if I resize the chart?
How can I get the
point.yaxis.l2p(point.pointNumber[0])
of a point that hasnât triggered the âplotly_hoverâ callback? Is there I way I can search for the updated pointâs data (maybe by where it is in the index of the array) after I call Plotly.relayout ?
thisLayer.on(âplotly_hoverâ (pointData) => {
const info = pointData.points.map((d) => {
const yaxis = pointData.points[0].yaxis;
const xaxis = pointData.points[0].xaxis;
const distY = yaxis.l2p(d.y) + yaxis._offset; //
const distX = xaxis.l2p(d.x) + xaxis._offset;
this.tooltipStyle = âleft:â + distX + "px; " + âtop:â + distY + âpx;â;
}
});
This will work to calculate the exact point where the tooltip must be shown, but the thing is that you should avoid pointer events on the tooltip or it will blink when hovered . Just add âpointer-events: none;â to your tooltip css.
Hi @etienne,
Iâm also trying to implement a custom tooltip, but am having difficulty getting the pixel coordinate for non-numeric axes.
Eg: https://codepen.io/Person21/pen/evBeMr
The x-coordinate is undefined. This is because l2p returns BADNUM if the input is not a number.
Is there any way to get the pixel value for a non-numeric axis?
d2p seems could work for non-numeric axes. But I am not 100% sure.
Thanks, it works!
Just a note to anybody else who wants to use this: d2p is only available for plotly 1.21 and above.
Dear @etienne,
This thread is very helpful, I tried to replace the default tooltip with my customized one, it seems to work:
Let me know whether this is the correct way to customize the tooltip. Thanks.
Also my own tooltip doesnât seem to be as âstableâ as the original one, itâs very sensitive to mouse move, is there any way to fix this? Thank you!