0

There is onClick function in Chart.js documentation, http://www.chartjs.org/docs/#chart-configuration-common-chart-configuration it got called everytime an click on chart occurs, it looks like this:

options: {
    onClick: this.Function
  }

Function(event, array){
...
}

But then it is passing the entire context and how can I know which specific part of the chart got clicked?

2 Answers 2

4

I have found the answer:

options: {
   onClick: this.Function.bind(this),
}

Function(event, array) {
   let clickedElement = this.doughnutChart.getElementAtEvent(event);
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can do this

import { ChartEvent } from 'chart.js'

options: {
  onClick: this.Function
}

Function(evt: ChartEvent, i: []) {
...
}

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.