Chartjs-How to add a custom event on legend click

0👍

Try to use bind() to bind context to a function.

public pieChartOptions: ChartOptions = {
    responsive: true,
    legend: {
      position: 'left',
      onClick: this.handleClick.bind(this, event, item)
    },
    title: {text: '', display: true}
  };

  handleClick(ev, item): void {
     this.legendClick.emit(item.index)
  }

Leave a comment