Home › Forums › Chart Support › Toggle Series Not From Legend › Reply To: Toggle Series Not From Legend
@theo,
You can toggle the visibility of a dataSeries by setting visible property. Updating visible property programmatically on clicking legend or button should work fine in this case. Please find the code-snippet for toggling dataSeries below.
var button = document.getElementById( "toggleDataSeries" ); button.addEventListener( "click", toggleDataSeries); function toggleDataSeries(e) { var data = chart.data; for(var i = 0; i < data.length; i++) { chart.options.data[i].visible = !data[i].visible; } chart.render(); }
Please take a look at this JSFiddle for a working example with sample code.
— Shashi Ranjan Team CanvasJS