OnDeselect on mobile devices

I’m struggling to find a solution if such solution really exists.

I’m using react-plotly library and whilst on desktop, I don’t have any concerns on implementing, using and debugging it. But on mobile I have an unwanted behaviour when a user clicks on any chart data (graph, line), the same behaviour an onHover on desktop, the user sees a legend (data representation etc.). On desktop it automatically disappears onUnhover event. But on mobile it stays permanent and only changes when the user clicks another part of the chart.
The question I’m asking, is it possible to detect an outside click and deselect previously selected legend to make the graph clear of any selected info.

Thank you in advance.