Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
692 views
in Technique[技术] by (71.8m points)

typescript - how to hide specific dataset based on condition chartjs angular

I have created a simple doughnut chart using chartjs plugin in angular like the given screenshot below

1

now when the chart loads if the dataset value below 100 it should automatically hide like below

2

here is my complete code https://stackblitz.com/edit/ng2-charts-legend-with-value-hide

tried this piece of code which was taken from this reference https://jsfiddle.net/beaver71/00q06vjp/

pieChartData.data.forEach(function(ds) {
    ds.hidden = !ds.hidden;

still no luck please help me to solve this issue

question from:https://stackoverflow.com/questions/65932846/how-to-hide-specific-dataset-based-on-condition-chartjs-angular

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
      }
    })
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...