☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Getting coordinates of hovered data point in CustomJS

Community Supportcustomjs
cirnod
cirnod

It is possible to execute JavaScript code when the plot is clicked using a Tap event and CustomJS:

from bokeh.plotting import figure
from bokeh.events import Tap

p = figure(...)
p.js_on_event(Tap, CustomJS(args = args, code = js_code))

With cb_obj.x in the js_code JavaScript code, I can access the x-value of the data coordinates where the mouse pointer click happened in the plot.

Is there a way to get the x-value of the closest data point which is currently hovered? Of course this would only work if hovering is enabled and when the mouse pointer is close enough to a data point.

In a JS callback from CustomJSHover, there is the special_vars variable which provides the coordinates of the hovered data point with the data_x property. However, it seems that special_vars is not available in the CustomJS callback of a Tap event.

⌁   Link to post

End of archived discussion · Replies are disabled