How much data series do you have? It works fine for me with ~ 20 data series
Maybe try to change “if” condition with:
chart.options.data[key].visible = !chart.options.data[key].visible