Plot – Crosshair State / Event Listener

Is there any way with observable to get the hovered value when using the crosshair, to be displayed in other reactive elements? I’m trying to highlight a point on a map (maplibre, not Plot) depending on what point the observable crosshair is selecting / hovering over on a time series graph. I would use d3.mouse() but it doesn’t track the click action with the crosshair, which keeps the position fixed.

This is the effect I am trying to achieve: CleanShot 2024-01-10 at 21.43.55 · CleanShot Cloud

Any help appreciated!

Actually, the docs kind of answer my own question! (Just not in the same section) Apparently, you can just add an event listener.

chart.addEventListener("input", (event) => {
  console.log(chart.value);
});

You can prefix your cell name with viewof:

viewof chart = // ...

and access the value in other cells through

chart

Here is a brief intro:

1 Like