Chartjs-Chart js :Adding onclick event on slice of doughnut chart is not working in react-chartjs-2

0👍

You dont have access to ‘this’ in the function, so you can bind this or use an arrow function like below

      onClick: (evt, item) =>{
          this.check("source", this.state.data.datasets[0].data[item[0]._index]);
          console.log("test");
        },

Also you will have to call this.check and use this.state.data

Leave a comment