angularchart.jsng2-chartsangular-seed

How to embed chart.js in angular-seed


I'm trying to use ng2-charts in an SB-Admin-BS4-Angular-2 project and I get the following error

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

Now I embedded chart.js in tools/config/project.config.ts

{ src: 'chart.js/dist/Chart.min.js', inject: 'libs'}

it is working as expected. Now I built my project and I get the following error in build process

Error on fetch for ng2-charts.js

enter image description here

I have done some research and kept the following code in tools/config/seed.config.ts

SYSTEM_BUILDER_CONFIG->paths --> 'ng2-charts' : 'node_modules/ng2-charts/ng2-charts.js'

then the build was success, then I copied dist/prod folder in my tomcat server My App didn't loaded and I get the following error in browser console

Uncaught TypeError: n.map is not a function

Doing research, but unable to find it. Can any of you help me with this


Solution

  • Add { src: 'chart.js/dist/Chart.min.js', inject: 'libs'} in tools/config/project.config.ts -> this.NPM_DEPENDENCIES

    Add 'ng2-charts' : 'node_modules/ng2-charts/ng2-charts.js' in tools/config/seed.config.ts ->

    in SYSTEM_CONFIG_DEV // for dev

    in SYSTEM_BUILDER_CONFIG // for prod

    Note: angular version should be greater 2.3 // I got error for older versions