How to get a bar info by a call back

I have a bar chart with data such as x=["apple", "banana", "peach"] and top=[1, 2, 3]. Since bar chart does’nt support the SelectionGeometry event, I want to register a Tap event to get the bar info such as the x and y coordinates.

Since Tap event can give the click position, I want to compare the click position with the bars’ position, and return the bar info that matches the click position.

However, I have no idea how to get a collection of VBar glyphs with all the infomation such as position, line color, and so on.

It’s not really clear what your requirements are. Are you just after the selection index of the bar that gets tapped? Because all bar glyphs absolutely support that. But the information is on the selected.indices property of the CDS, not on the glyph. See:

https://docs.bokeh.org/en/latest/docs/user_guide/interaction/js_callbacks.html#customjs-for-selections

That example uses a lasso for selection, but a TapTool behaves identically.

That’s what I want. For example, if I click the “apple” bar, a call back can be called to return the bar’s info such as x=apple, top=1as well as other visual properties like bar color.

You mean I should register the call back for CDS’s selected event?

source.selected.js_on_change('indices', CustomJS(...))

like in the example linked above. Inside the CustomJS you can access the index for which bar was clicked, and then you can use this index to index into CDS columns for color or coordinate.

Thanks for your clarification. I’ll try it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.