I had this problem using <p-chart> primeNG.

Just add this in your index.html:

<script src= "" charset="utf-8"></script>

And that´s it, you don´t have to import in your typescript.

I found that in chart documentation

-then use a Chart.js CDN.


I tried. this works for me easy to implements


If you are using webpack you may try adding the chart.js file (or the minified version) to the entry property as follows:

entry: {
      'chartJS': './node_modules/chart.js/dist/Chart.bundle.min.js',
      // Other mappings


Here is the best module out of few on npmjs:


Then you can use it like this in your module:

import { ChartModule } from 'angular2-chartjs';

  imports: [ ChartModule ]
  // ...
export class AppModule {

And in html template:

<chart [type]="type" [data]="data" [options]="options"></chart>

Don't forget to fill it with data ;)


In the template don't forget to enclose canvas in a div. If canvas is a direct child of custom directive in dom, then chart might not load.

<div><canvas id="myChart"></canvas></div>

I have wasted lot of time in finding this issue.


I had a similar issue, it turned out I was referencing an old example.

First, as you've already correctly done, install the library using NPM:

npm install chart.js --save

Then, in your component, import the library:

import Chart from 'chart.js';

To get up and running with a quick example, have a look at the example code in the Chart.js documentation or see my example below.


import Chart from 'chart.js';
import { ViewChild, Component, ElementRef, OnInit } from '@angular/core';

    selector: 'app-dashboard',
    template: '<canvas #donut></canvas>'

export class DashboardComponent implements OnInit {
    @ViewChild('donut') donut: ElementRef;

    ) { }

    ngOnInit() {
        let donutCtx = this.donut.nativeElement.getContext('2d');

        var data = {
            labels: [
                "Value A",
                "Value B"
            datasets: [
                    "data": [101342, 55342],   // Example data
                    "backgroundColor": [

        var chart = new Chart(
                "type": 'doughnut',
                "data": data,
                "options": {
                    "cutoutPercentage": 50,
                    "animation": {
                        "animateScale": true,
                        "animateRotate": false

Related Query

More Query from same tag