Click event on a trace

Hello everyone,
i would like add an event when i click on a trace.
for exemple when i click on a trace, i show an alert “you click on trace X”.

Thanks everyone.

var gd = document.getElementById('graph')
Plotly.newPlot(gd, [], {})
gd.on('plotly_click', () => {})

should do the trick.

yes but this it’s if i click on a point .

here i would like that if i click on red trace there an alert but not on black point

Ha, we don’t expose a way to that at the moment.

You can subscribe to for the most up-to-date development info.

Ok, thank for your help :slight_smile: