Chartjs-Chart.js onClick event function, access angular component

0👍

If you write, onClick: () => {}, this will be the component/class when writing an arrow function.

If you write, onClick: function() {}, this will be the chart object.

If you want access to both the chart object and component/class, I would use the utility of thisAsThat linked below and explained as well.

TypeScript: How to use both fat arrow and this?

For onClick: you can use the utility of thisAsThat that’s present in the answer where this will be the class/component and that will be the chart object.

I would also consider using ng2-charts which is a wrapper around chart.js where it has a (chartClicked) event.

Chart.js & Angular 2 – ng2-charts Custom on Click Event

Leave a comment