Changing graph tooltip values based on input?

Hi there, I’ve created a notebook that imports labor market data from Google Sheets and allows the user to select the measure of interest from a dropdown (right now it’s just two measures). Dashboard / Berkeley Institute for Young Americans | Observable

I can’t figure out how to have the tooltip values reflect the user input from the dropdown and, therefore, the measure being visualized.

The relevant code within the visualization is:
title: (d) =>
${d.unrate}% \n ${d.division} \n ${d.month} ${d.year} // \n makes a new line
}),

I tried:
title: ${Object.values(favorite)[1]}

That worked, but I wasn’t able to figure out how to add other text to the tooltip.

Any help is appreciated!

1 Like

I guess you could just combine those:

  title: (d) =>
    `${Object.values(favorite)[1]} \n ${d.unrate}% \n ${d.division} \n ${d.month} ${d.year} ` // \n makes a new line
  }),

I think it might be a bit more common, though, to refer to an object property, like favorite.name; the result looks pretty good too:

  title: (d) =>
    `${favorite.name} \n ${d.unrate}% \n ${d.division} \n ${d.month} ${d.year} ` // \n makes a new line
  }),
2 Likes

Yes, this worked perfectly! Thank you, Mark!

1 Like