You must be logged in to post your query.
Home › Forums › Chart Support › Toggle Series Not From Legend
Tagged: Toggle Series without legend
Hi,
I have a chart that I’m not using the built in legend for and I want to be able to toggle the series.
How can I do this?
@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
You must be logged in to reply to this topic. Login/Register