'onClick function in Chart.js passing the selected object, Typescript
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?
Solution 1:[1]
I have found the answer:
options: {
onClick: this.Function.bind(this),
}
Function(event, array) {
let clickedElement = this.doughnutChart.getElementAtEvent(event);
}
Solution 2:[2]
You can do this
import { ChartEvent } from 'chart.js'
options: {
onClick: this.Function
}
Function(evt: ChartEvent, i: []) {
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Iqbal Muhammad |
