chartjs-plugin-datalabels has dependency on chartjs >= 2.7. My setup was with n2-charts 1.5 but updated the chartjs to 2.7.1. The labels works fine by including in the options something like:
plugins: {
datalabels: {
display: true,
formatter: function (value) {
return this.formatValue(value);
}.bind(this)
}
}
Then I updated ng2-charts to 1.6 and the labels no longer show up. I didn't realize this until I tried to downgrade to 1.5 and notice it work again.
core.js:1350 ERROR TypeError: Cannot read property 'data' of undefined
same issue with 1.6
I must be using it wrong, coz it does work with v1.6
I have the same problem, only got it working with v1.5
Add this line on the top of your app.module.ts file
import '../../node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.js';
it worked for me.
@raminassar Thank you! That solved my problem!
I was getting this error when trying to import in an bar graph component..
Module not found: Error: Can't resolve '../../node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.js'
Most helpful comment
Add this line on the top of your app.module.ts file
import '../../node_modules/chartjs-plugin-datalabels/dist/chartjs-plugin-datalabels.js';it worked for me.