1👍
You’re using this
inside a callback function which will reset the scope of this
.
To use the correct scope, change that to an array function. Something like this:
var myDoughnutChart = new Chart(ctx, {
fontSize: () => {
if (this.width <= 768) {
return 10;
} else {
return 13;
}
},
}
}
UPDATE:
Directly accessing the window
object isn’t really recommended as window
is a Browser based API and your application might run on Angular Universal(in the near future may be) where it might not have access to the Browser based APIs like window
.
Please consider following this pattern suggested by Brian Love in this article: Angular Window Provider
I know this might sound overwhelming at first but this is the safest way to go about doing it.
- Chartjs-How to use output of JSON.parse() as a input of HTML charts' data field?
- Chartjs-Draw a single frame in Chart.js
Source:stackexchange.com