ChristoK ChristoK - 3 years ago 133
TypeScript Question

How to inject data into chartjs plugin function?

I have the following chart with plugin function:

this.doughnutChart = new Chart(this.doughnutCanvas.nativeElement, {

type: 'doughnut',
plugins: {
beforeDraw: function (chart) {
//I want to use data here

Data from a provider:

constructor(public dataService: Data)

And data is easily accessible from the class where chart and plugin is located, but I dont know how to inject it inside of plugin function.

Answer Source

I have found the answer, everything is in the 'chart' parameter just deep inside:;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download