Incorporating the chartjs-plugin-annotation, I am faced with the need to trigger an event once a user clicks on an annotation to display a tooltip text. The plugin offers an event handler for the click event that allows me to retrieve the clicked element:
onClick: function(e) {
let identifier = this.id; // identifier stores the reference to the clicked element in the DOM
}
However, my requirement is to pass this variable to a method in a different namespace (Window). To achieve this, I can utilize the following approach to access the method:
onClick: (e) => {
this.functionToBeCalled(e);
return;
}
The problem lies in the first script, where "this" is associated with the callback function. Conversely, in the second script, I can access the function but lack reference to the element that needs to be passed.
How can I address this issue?