Vega-lite: concatenate fields for a tooltip

Hi all,
I have a very basic and I think stupid question.
I’m doing the first steps in observablehq and vega-lite.
I have forked a choropleth map notebook, and I have edit it a little:

  • I have changed the source data file
    • the former one does not have the state name
  • I have set the state name as tooltip.

How can I concatenate two fields name and delta and use the output as tooltip?

Thank you

hi @aborruso, you probably want to do this

      vl.tooltip([vl.fieldN('name'),vl.fieldQ('delta')])

you can see more examples here

1 Like

It works great thank you.

And what’s the way to have something like “state name, delta”, something like “Clark, 0.022”.

Best regards

It doesn’t look easy to me from reading the docs. Because they are objects being parsed to the tooltip each key-value pair is displayed in its own row.
Arrays will be shown in line, but I don’t know how it convert from the two objects into and array.

https://github.com/vega/vega-tooltip/blob/master/docs/creating_your_tooltip.md#step-4-define-your-tooltip-in-vega-or-vega-lite

I typed to be a bit hackery by using the forced ‘title’ to inject the name, but it’s an object and not the name.

vl.tooltip([{'field': 'delta','title':{'field': 'name'}}])
2 Likes