3 thoughts on “is it possible to toggle legend items programatically?

  1. For me it worked to use this:

    //Hide
    chart.getDatasetMeta(1).hidden=true;
    chart.update();
    
    //Show
    chart.getDatasetMeta(1).hidden=null;
    chart.update();

    Where 1 is the index of RGB in the dataset.

  2. @mennodekker is right. Just one point: instead of null, better to use false.

    The reason is that if the dataset is hidden in the first place, programmatically setting hidden to null won’t actually show the dataset.

    //Hide
    chart.getDatasetMeta(1).hidden=true;
    chart.update();
    
    //Show
    chart.getDatasetMeta(1).hidden=false;
    chart.update();
  3. I’m actually facing a similar issue. I”ve make a custom legend component and I’m able to show/hide using the above codes. However, this only works for bar chart. It raise the following exception when using it with donut chart:

    TypeError: Cannot read property '_meta' of undefined at Chart.getDatasetMeta (core.controller.js:656)

    Have anyone faced a similar issue please?

Comments are closed.