# How to detect when a trace visibility status is changed?

**URL:** <https://community.plotly.com/t/how-to-detect-when-a-trace-visibility-status-is-changed/9217>\
**Category:** plotly.js\
**Created:** [March 26, 2018, 4:52pm UTC](https://community.plotly.com/t/how-to-detect-when-a-trace-visibility-status-is-changed/9217 "2018-03-26T16:52:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobq](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jacobq/32/2663_2.png) [@jacobq](https://community.plotly.com/u/jacobq)\
**Post date:** [March 26, 2018, 4:52pm UTC](https://community.plotly.com/t/how-to-detect-when-a-trace-visibility-status-is-changed/9217/1 "2018-03-26T16:52:13Z")

</div>

I would like to be able to save the visibility state (i.e. shown or hidden) associated with each trace so that when the plot needs to be redrawn (e.g. user navigates to another view in the app then comes back to one that uses plotly.js) the app can set `visibility: 'legendonly'` on the traces that the user had previously hidden.

It looks like the [`plotly_restyle` event fires in this case](https://output.jsbin.com/lafunef/3), and I can see the update in the [`eventData`](https://plot.ly/javascript/plotlyjs-events/#update-data). Is that the recommended way to do this (or at least an appropriate place to put the related code)?

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [March 26, 2018, 5:17pm UTC](https://community.plotly.com/t/how-to-detect-when-a-trace-visibility-status-is-changed/9217/2 "2018-03-26T17:17:04Z")

</div>

> the app can set visibility: ‘legendonly’ on the traces that the user had previously hidden.

I think you’re looking for `visible: 'legendonly'`. `visibility` isn’t a proper plotly.js attribute.

> [@jacobq](#):
>
> Is that the recommended way to do this (or at least an appropriate place to put the related code)?

Yes.

---

<div class="post-metadata">

**Author:** ![jacobq](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jacobq/32/2663_2.png) [@jacobq](https://community.plotly.com/u/jacobq)\
**Post date:** [March 26, 2018, 5:28pm UTC](https://community.plotly.com/t/how-to-detect-when-a-trace-visibility-status-is-changed/9217/3 "2018-03-26T17:28:06Z")

</div>

Oops, yes, I meant `visible` (Freudian slip from CSS ;D)
