Ng2-charts: chartjs-plugin-datalabels not working in 1.6 but works in 1.5

Created on 30 Nov 2017  路  5Comments  路  Source: valor-software/ng2-charts

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.

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.

All 5 comments

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'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hggeorgiev picture hggeorgiev  路  4Comments

egervari picture egervari  路  4Comments

Maistho picture Maistho  路  3Comments

Adwind picture Adwind  路  3Comments

vmironovs picture vmironovs  路  3Comments