JavaScript config, change between 'Show closest data on hover' and 'Compare data on hover'

I need to switch between these 2 modes from JavaScript code:
image

I’ve consulted this: plot . ly/javascript/configuration-options/

And then the config object source code here: https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js#L22-L86

Where it appears there’s no option to set so.

Is there anyway I can access this portion of the code: https://github.com/plotly/plotly.js/blob/master/src/components/modebar/buttons.js#L173-L193

Using Plotly.React when refreshing the chart?

Use case is: user clicks a button and either only 2 lines are drawn or many more. First case needs “compare data” and second one needs “show closest”. By default it is always set to “compare” which is tedious if the user pulls the data many times, as he has to switch mode after every refresh.

Hmm.

Have you tried setting layout.hovermode to 'closest'?

1 Like
three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online