Primeng: Chart is not defined error

Created on 21 Mar 2016  路  20Comments  路  Source: primefaces/primeng

when we try to use doughnutChart component following error occurs;

angular2.dev.js:23730 ReferenceError: Chart is not defined
    at DoughnutChart.initChart (http://localhost:8080/node_modules/primeng/components/chart/doughnutchart/doughnutchart.js:91:30)
    at DoughnutChart.ngAfterViewInit (http://localhost:8080/node_modules/primeng/components/chart/doughnutchart/doughnutchart.js:62:14)
    at AbstractChangeDetector.ChangeDetector_FrontPageComponent_0.afterViewLifecycleCallbacksInternal (viewFactory_FrontPageComponent:119:82)
    at AbstractChangeDetector.afterViewLifecycleCallbacks (http://localhost:8080/node_modules/angular2/bundles/angular2.dev.js:9924:12)
"angular2": "2.0.0-beta.11",
"primeng": "^0.8.1",
"primeui": "^4.1.5"

Most helpful comment

Adding:

  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.bundle.min.js"></script>

To my index.html page, resolved this issue for me.

All 20 comments

Welcome to PrimeNG, you also need to add charts.js to your page.

I've got the same Problem. chart.js implemented before angular-chartjs.

Chart is not defined. Error occurs within my .html.

@cagataycivici
Could you please give a working example of chart using primeng ?
and from where we have to add chart.js ?

@abbas-innotical
Could you please give a working example of chart using primeng ?
and from where we have to add chart.js ?

I would also like to see a working example of chart using primeng in order to see how to add it.

Adding:

  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.bundle.min.js"></script>

To my index.html page, resolved this issue for me.

Y'know, the fact you have to import Chart.js isn't really mentioned on the showcase...

wow thank you , I would never have found this out.

Hi!
I am working with angular (v2+) in Typescript, I added:

npm install --save chart.js
npm install --save-dev @types/chart.js

But still couldn't work with a simple:
import { Chart } from 'chart.js';
I have an issue. It seems chart.js is not typescript friendly..

is there a way to load via angular cli? kinda sucks putting

Yes;

 "scripts": [
          "../node_modules/chart.js/dist/Chart.js",
          //..others
      ],

Added this info to chart docs as well.

it doesn't work this way may be because the scripts are loaded at the bottom of the page

image

hm yeah that works indeed https://github.com/intergleam/test-primeng

In .angular-cli.json i add :+1: "scripts": [
"../node_modules/chart.js/dist/Chart.js"
],
I get this issue : ERROR in multi script-loader!./~/chart.js/dist/Chart.js
Module not found: Error

@cagataycivici where can i find the to chart docs in your post on 11 march ?

I had a similar issue ReferenceError: Chart is not defined funny thing was, that i had to change the order of how my javascript was loaded (same issue i had before with quill.js)

What i did:
added ChartModule to my module.ts (plus imports)

installed chart.js

npm install --save chart.js
npm install --save-dev @types/chart.js

added script to .angular-cli.json

NOT WORKING (in .angular-cli.json)


"../node_modules/quill/dist/quill.js",
"../node_modules/angular2-indexeddb/angular2-indexeddb.js",
"../node_modules/chart.js/dist/Chart.bundle.js"

WORKING (in .angular-cli.json)


"../node_modules/quill/dist/quill.js",
"../node_modules/chart.js/dist/Chart.bundle.js",
"../node_modules/angular2-indexeddb/angular2-indexeddb.js"

I do not really have an idea why it is like that... but that worked for me..

@jwiesmann thanks ! :)

  1. In package.json add at the _dependencies_

"chart.js": "^2.7.2",

  1. In angular.json add at the _scripts_

"./node_modules/chart.js/dist/Chart.js"

  1. _run_ npm install

Thanks! The docs should really be updated about installation. I only needed ng prime charts and ran into the same issue. @kosnet2 solution for the win

Was this page helpful?
0 / 5 - 0 ratings

Related issues

watalberto picture watalberto  路  3Comments

KannanMuruganmony picture KannanMuruganmony  路  3Comments

Helayxa picture Helayxa  路  3Comments

SchneMa picture SchneMa  路  3Comments

Helayxa picture Helayxa  路  3Comments