Ng2-charts: Not working with angular-cli 1.0.0-beta.18

Created on 25 Oct 2016  Â·  7Comments  Â·  Source: valor-software/ng2-charts

angular-cli: 1.0.0-beta.18
node: 6.9.1
os: win32 x64

AppModule

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

 imports: [
    ChartsModule
  ],

angular-cli.json

 "scripts": [
          "../node_modules/jquery/dist/jquery.js",
          "../semantic/dist/packaged/semantic.js",
          "../node_modules/chart.js/dist/Chart.bundled.js",
          "../node_modules/ng2-charts/bundles/ng2-charts.js"
      ]

I get this error

Uncaught ReferenceError: System is not defined(…)(anonymous function)
@ VM218:1module.exports
@ addScript.js:9453
@ ng2-charts.js?02df:1__webpack_require__
@ bootstrap b07eb3e…:521070
@ scripts.bundle.js:9__webpack_require__
@ bootstrap b07eb3e…:52webpackJsonpCallback
@ bootstrap b07eb3e…:23(anonymous function)
@ scripts.bundle.js:1

Additional info:
package.json

{
  "name": "frontend",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~2.1.1",
    "@angular/compiler": "~2.1.1",
    "@angular/core": "~2.1.1",
    "@angular/forms": "~2.1.1",
    "@angular/http": "~2.1.1",
    "@angular/platform-browser": "~2.1.1",
    "@angular/platform-browser-dynamic": "~2.1.1",
    "@angular/router": "~3.1.1",
    "chart.js": "^2.3.0",
    "core-js": "^2.4.1",
    "jquery": "^3.1.1",
    "ng2-charts": "^1.4.0",
    "rxjs": "5.0.0-beta.12",
    "semantic-ui": "^2.2.4",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.18",
    "codelyzer": "1.0.0-beta.1",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "~2.0.3"
  }
}

Most helpful comment

This worked for me:
In angular-cli.json, only declare "../node_modules/chart.js/dist/Chart.bundle.js" , not "../node_modules/ng2-charts/bundles/ng2-charts.js"
"scripts": [ "../node_modules/chart.js/dist/Chart.bundle.js" ],
And in template
<canvas class="chart" [datasets]="datasets" [labels]="labels" [options]="options" [chartType]="'line'" baseChart> </canvas>

All 7 comments

same case here, not working with angular-cli

i resolved this by changing in template

change:

<base-chart
      class="chart"
      [datasets]="datasets"
      [labels]="labels"
      [options]="options"
      [chartType]="'line'">
 </base-chart>

to:

<canvas
      class="chart"
      [datasets]="datasets"
      [labels]="labels"
      [options]="options"
      [chartType]="'line'"
      baseChart
 ></canvas>

This worked for me:
In angular-cli.json, only declare "../node_modules/chart.js/dist/Chart.bundle.js" , not "../node_modules/ng2-charts/bundles/ng2-charts.js"
"scripts": [ "../node_modules/chart.js/dist/Chart.bundle.js" ],
And in template
<canvas class="chart" [datasets]="datasets" [labels]="labels" [options]="options" [chartType]="'line'" baseChart> </canvas>

I was finally able to make it work by refactoring my navigation back to app.module i will get back to you with more details if i am able to make it work again with separate routing module.

qpdian comment helped

Had the same problem. Fixed it in 1 mn using either Highcharts or emn178 Chart.js directive for ng2, which just work out of the box. I'm done struggling with this library ...

This looks like an async issue with the angular-cli script loader; it has worked for me, but only sometimes. I get ng2-charts configuration issue: Embedding Chart.js lib is mandatory

Obsolete issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brandonreid picture brandonreid  Â·  3Comments

Adwind picture Adwind  Â·  3Comments

tushartgsit picture tushartgsit  Â·  5Comments

alexcastillo picture alexcastillo  Â·  5Comments

raychenfj picture raychenfj  Â·  3Comments