Home Forums Chart Support Toggle Series Not From Legend

Toggle Series Not From Legend

Viewing 2 posts - 1 through 2 (of 2 total)
  • #33331

    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?

    #33421

    @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.
    Hide/Unhide entire Dataseries from a Button


    Shashi Ranjan
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.