Getting error using ng2 charts with Angular 2 RC 6.

1,081 views
Skip to first unread message

Santosh Pillai

unread,
Sep 11, 2016, 2:47:37 AM9/11/16
to AngularJS
Hi,

I'm new to angular. I'm trying to use the Ng2 charts, a third party library,  in my application to display data in charts. This is what I've done so far. 

1. Installed ng2 charts into the project. 

    npm install ng2-charts --save


2. Installed chart js 

   npm install chart.js --save


3. Added cdn link to the index.html

  <link href= "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.js">


4.Performed following to add 3rd party library to the project:

  a) In System-config.ts file added following:


        const map: any = {

             'ng2-charts': 'vendor/ng2-charts'

         };


       const packages: any = {

         "ng2-charts": { main: 'ng2-charts.js' }

      };



  b) in the 'angular-cli-build.js' added following:

       ng2-charts/**/*.js'


5. Then in the 'app.module.ts' file :

    a) When I use the following the import the project:

      import { CHART_DIRECTIVES  } from 'ng2-charts/ng2-charts';

      it displays an error that there is no exported member  'CHART_DIRECTIVES' 

  

    b) so I replaced 'CHART_ DIRECTIVES' with 'ChartsModule' and it works fine till now. 


Here is where I'm stuck:


When I see my project in the browser, I get the following error: 


"zone.js:101 GET http://localhost:4200/node_modules/ng2-charts/ng2-charts.js 404 (Not Found)" 


Please refer screenshot for the complete list of errors that I get. 


Can any please help me out with this.. Thanks. 



Zlatko Đurić

unread,
Sep 12, 2016, 3:21:03 AM9/12/16
to AngularJS
Did you create this project with angular2-cli tool? Did you change the System.js config default stuff? Because the  ` const map: any = { 'ng2-charts': 'vendor/ng2-charts'  };` part should, by default, be done in `src/app/system-config.ts`. You already have a System.config({ map, packages }) there. Try simply adding ng2-charts there instead of index.html, it could work.

Also, a side note, you can install chart.js with npm too, to avoid the extra CDN link.

Santosh Pillai

unread,
Sep 15, 2016, 10:24:19 AM9/15/16
to AngularJS

Hi

Thanks for your time. Yes, created this project with angular2-cli tool.
It works fine now with RC 6, I'm able to use Ng 2 charts. Now, I would try this out with latest (Released) version of Angular2.

Thanks.

Santosh Pillai

unread,
Sep 21, 2016, 1:52:52 AM9/21/16
to AngularJS
Hi, 

I tried importing Ng2 charts for Released Version of Angular 2 . The commands to add ng2 charts in nodes_module is giving me a whole bunch of  errors.  Please refer screenshot below.  Is anyone facing the same error ?  is Ng2 Supported with release version of Angular 2?

    npm install ng2-charts --save

    npm install chart.js --save

Screen Shot 2016-09-21 at 11.21.32 AM.png

Lucas Lacroix

unread,
Sep 21, 2016, 6:55:27 AM9/21/16
to AngularJS
It looks like ng2-charts was last updated to support rc6. I would guess you have a different rc installed or you have the release installed.
ng2-charts may or may not work. There were not many (if any) breaking changes in rc6/rc7 so it may still work, even with these errors.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
--
Lucas Lacroix
Computer Scientist
Advanced Technology Division, MEDITECH
Reply all
Reply to author
Forward
0 new messages