Showing both x and y value in multi-line tooltip
See original GitHub issueHello, thanks for your work on this awesome visualization library.
I am looking to adapt the multi-line tooltip example (https://altair-viz.github.io/gallery/multiline_tooltip.html) to plot molecular spectra. I would like the tooltip to also show the value of the x axis. I’ve added another text mark:
x_text = spectrum.mark_text(align="right", dx=-5, dy=-25).encode(
text=alt.condition(nearest, "x:Q", alt.value(" "), format="3.4f")
)
but was wondering:
a. Is there a better way to do this?
b. How can I have the displayed x-value always appear at the bottom (or top) of the chart without fiddling with dx
and dy
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Multi-Line Tooltip — Altair 4.2.0 documentation
Multi-Line Tooltip . This example shows how you can use selections and layers to create a tooltip-like behavior tied to the x position...
Read more >How to show values on hover for multiple line graphs - Bokeh
This argument accepts the same values as the HoverTool.tooltips property. If a hover tool is specified in the tools argument, this value ...
Read more >Line Chart, Multiple Series, with tooltip - Observable
Having multiline tooltips means a better capability for displaying data, ... x = ([x]) => x, // given d in data, returns the...
Read more >PDF form fields | Add tooltips, data and time, reqired/optional ...
Learn how to use form fields properties to add tooltip, date & time, required or not required, multi-line text, and calculated values in...
Read more >Configuring plot tools — Bokeh 2.4.3 Documentation
The hover tooltip shows the index of the image, the name of the pattern, the x and y position of the cursor, as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, I’ve been meaning to replace that example because it’s overly verbose and confusing. With the pivot transform in Altair 4+, you can do something a bit more cleanly:
This makes it trivial to add another tooltip field: just add an encoding to the list.
You’re pivoting x while grouping by x, which constructs an NxN data representation. Here N is 5000, so you’re telling the browser to construct a data object with 25,000,000 elements.
That is… not recommended.
There’s no reason to pivot a value while grouping by that same value. And if all you want is to display a tooltip with x and y, there’s no need to pivot at all. Remove the pivot transform and it should work.