Ng2-charts: ionic 2 RC1: embedding chart.js lib is mandatory

Created on 16 Nov 2016  路  3Comments  路  Source: valor-software/ng2-charts

Reproduction of the problem
Hi, I'm trying to use ng2-charts in an ionic 2 project and I get the following error:

Error: ng2-charts configuration issue: Embedding Chart.js lib is mandatory
Versions:

  • Ionic 2: 2.0.0-rc.1
  • Angular 2: 2.0.0
  • chart.js": 2.4.0
  • ng2-charts: 1.4.1

Unfortunately the workarounds on #458 didn't help. Are there any workarounds to this problem?
Thank you!

Most helpful comment

adding

import '../../node_modules/chart.js/dist/Chart.bundle.min.js'; // and
import { ChartsModule } from 'ng2-charts/components/charts/charts';

to the app.module.ts fixed the problem. I guess this bug makes more sense on the ionic github repository, since it seems to be that ionic 2 isn't properly including some packages.

All 3 comments

adding

import '../../node_modules/chart.js/dist/Chart.bundle.min.js'; // and
import { ChartsModule } from 'ng2-charts/components/charts/charts';

to the app.module.ts fixed the problem. I guess this bug makes more sense on the ionic github repository, since it seems to be that ionic 2 isn't properly including some packages.

@martinpinto

We should not include directly in app.module like the way you did for chart.js

chart.js doesn't support commonjs modules so added them in the project.config file under NPM_DEPENDENCIES

the best way i prefer is this.

  `  this.NPM_DEPENDENCIES = [              
       ...this.NPM_DEPENDENCIES,
       {src: 'jquery/dist/jquery.min.js', inject: 'libs'},
       {src: 'lodash/lodash.min.js', inject: 'libs'},
       {src: 'chart.js/dist/Chart.min.js', inject: 'libs'}, 
];`

libs, the dependency will be injected into the <!-- libs:js --> section of the index file.

if you are using an angular-seed this is the best practice to add external libs

Hi,
I am gettting error in Ionic 2 application using chart.js
Uncaught Error: Can't resolve all parameters for Chart: (?, ?)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mrpotato3 picture mrpotato3  路  5Comments

hggeorgiev picture hggeorgiev  路  4Comments

Maistho picture Maistho  路  3Comments

shyamal890 picture shyamal890  路  4Comments

egervari picture egervari  路  4Comments