[Chartjs]-How to hide specific dataset based on condition chartjs angular

0👍

Update your ngOnInit on stackBlitz and see if this is what you want

ngOnInit() {
    const othis = this;
    this.pieChartData.forEach((data, i) => {
      if (data < 100) {
        othis.pieChartData.splice(i, 1);
      }
    })
  }

0👍

If you have access to the chart object from the wrapper you can hide the dataset this way:

if (data < 100) {
  chartObject.getDatasetMeta(2).hidden = true
  chartObject.update()
}

But im not fammiliar with the ng wrapper so I dont know if they exposed the chart object. If this is not the case you might want to look into using only the normal lib and writing your own wrapper component.

Edit: According to this thread it is possible to acces the chart object (ng2-charts access base chart object)

0👍

When you set your data, you probably have something like this:

this.barChartData = [
    { data:[1, 2, 3], label: 'legend'}
];

you can add one parameter entitled hidden :

this.barChartData = [
    { data:[1, 2, 3], label: 'legend', hidden: true }
];

instead of "true", you can probably run a test and beforehand and store the result in a variable.

Leave a comment