# 'plotly\_hover' not working after replotting new data in same div with Plotly.newPlot

**URL:** <https://community.plotly.com/t/plotly-hover-not-working-after-replotting-new-data-in-same-div-with-plotly-newplot/42425>\
**Category:** plotly.js\
**Created:** [July 13, 2020, 9:40pm UTC](https://community.plotly.com/t/plotly-hover-not-working-after-replotting-new-data-in-same-div-with-plotly-newplot/42425 "2020-07-13T21:40:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IanFlitcroft](https://avatars.discourse-cdn.com/v4/letter/i/f04885/32.png) [@IanFlitcroft](https://community.plotly.com/u/IanFlitcroft)\
**Post date:** [July 13, 2020, 9:40pm UTC](https://community.plotly.com/t/plotly-hover-not-working-after-replotting-new-data-in-same-div-with-plotly-newplot/42425/1 "2020-07-13T21:40:45Z")

</div>

My hover over info box works fine until I replot data after updating the data array with

Plotly.newPlot(‘graph’, data, layout, {displayModeBar: false});

my code outline:

var data = [data1, data2, data3, data4];  
var hoverInfo = document.getElementById(‘hoverinfo’);  
var myPlot = document.getElementById(‘graph’);  
Plotly.newPlot(‘graph’, data, layout, {displayModeBar: false});

myPlot.on(‘plotly\_hover’, function(data){  
…my hover stuff…  
});

I can’t find a way of using Plotly.restyle to update the entire data array.  
I tried this which looks like it should work. It changes things but breaks the graph completely.

```
        Plotly.restyle('graph', data1, [0]);
        Plotly.restyle('graph', data2, [1]);
        Plotly.restyle('graph', data3, [2]);
        Plotly.restyle('graph', data4, [3]);
```

---

<div class="post-metadata">

**Author:** ![koushikphy](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@koushikphy](https://community.plotly.com/u/koushikphy)\
**Post date:** [July 15, 2020, 5:01am UTC](https://community.plotly.com/t/plotly-hover-not-working-after-replotting-new-data-in-same-div-with-plotly-newplot/42425/2 "2020-07-15T05:01:33Z")

</div>

It would remove the event listner if you create the new plot, its the expected behavior. You have to attach the event listener again.

To restyle multiple data trace do this, if its a simple 2d scatter plot and  
`data1 = {x:[1,2,3], y: [4,5,6]}` and `data2 = {x:[3,4,5], y:[9,2,1]}`

```auto
Plotly.restyle(graph,{ x :[[1,2,3],[3,4,5]], y:[[4,6,8],[9,2,1]]})

```
