Accepted answer

try importing chartsmodule in your app.module.ts like this-

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

imports: [


in my case i had to change how i import and a little change in my html file tag:


import {component} from '@angular/core';
import {chart_directives} from 'ng2-charts/ng2-charts';

    selector: 'chart-balance',
    template: require('./templates/chart-balance.template'),
    styles: [`.chart {display: block; width: 100%;}`],
    directives: [chart_directives]

export class chartbalancecomponent {
    public barchartoptions:any = {
        scaleshowverticallines: false,
        responsive: true,
        scales: {
            yaxes: [{
                ticks: {
                    beginatzero: true,
                    callback: label => `${label.tolocalestring()}`
    public barchartlabels:string[] = ['2014', '2015', '2016'];
    public barcharttype:string = 'bar';
    public barchartlegend:boolean = true;

    public barchartdata:any[] = [
        {data: [32131, 3432, 543], label:'test 1'},
        {data: [54353, 432, 768], label:'test 2'}

    // events
    public chartclicked(e:any):void {

    public charthovered(e:any):void {


here was another change i did:

notice -- > base-chart class="chart" ...


<base-chart class="chart"


export * from './components/charts/charts';
declare var _default: {
    directives: any[][];
export default _default;


import { ondestroy, oninit, onchanges, eventemitter, elementref } from '@angular/core';
export declare class basechartcomponent implements ondestroy, onchanges, oninit {
    static defaultcolors: array<number[]>;
    data: number[] | array<number[]>;
    datasets: any[];
    labels: array<any>;
    options: any;
    charttype: string;
    colors: array<any>;
    legend: boolean;
    chartclick: eventemitter<any>;
    charthover: eventemitter<any>;
    private ctx;
    private cvs;
    private parent;
    private chart;
    private initflag;
    private element;
    constructor(element: elementref);
    ngoninit(): any;
    ngonchanges(): any;
    ngondestroy(): any;
    getchartbuilder(ctx: any): any;
    private refresh();
export interface color {
    backgroundcolor?: string | string[];
    borderwidth?: number | number[];
    bordercolor?: string | string[];
    bordercapstyle?: string;
    borderdash?: number[];
    borderdashoffset?: number;
    borderjoinstyle?: string;
    pointbordercolor?: string | string[];
    pointbackgroundcolor?: string | string[];
    pointborderwidth?: number | number[];
    pointradius?: number | number[];
    pointhoverradius?: number | number[];
    pointhitradius?: number | number[];
    pointhoverbackgroundcolor?: string | string[];
    pointhoverbordercolor?: string | string[];
    pointhoverborderwidth?: number | number[];
    pointstyle?: string | string[];
    hoverbackgroundcolor?: string | string[];
    hoverbordercolor?: string | string[];
    hoverborderwidth?: number;
export interface colors extends color {
    data?: number[];
    label?: string;
export declare const chart_directives: array<any>;


instead of importing the chartsmodule in app module, import it in inside module where your are using. for example, home module (if using charts in home page).


in case you are using a shared module, you also need to export the chartsmodule from there, to make it available to all your components which use your shared module.

// simplified module only showing what's important for chartsmodule
import { ngmodule } from '@angular/core';
import { chartsmodule } from 'ng2-charts';

    declarations: [],
    imports: [chartsmodule],
    exports: [chartsmodule]

export class sharedmodule {
    static forroot(): modulewithproviders<sharedmodule> {
        return {
            ngmodule: sharedmodule


in my case, it was nothing to do with including chartsmodule in multiple modules or exporting it.

i had created a chart component that used ng-chart and then found i needed another version of it. so i copied the component, renamed the class and template file, but forgot to update the templateurl property in the @component decorator.

having two different components referencing the same template file gave the exact same error:

can't bind to 'datasets' since it isn't a known property of 'canvas'

as soon as i changed the new component to use the correct html template, the error was resolved.

fyi, i reference chartsmodule as shown in @sanket's answer in the module of my chart components and the module of the page components that reference them (so it's not needed in appmodule).


if your component is declared in another module other than app.module.ts you will simply do the following:


import { chartsmodule } from 'ng2-charts';



   imports: [
export class appmodule{ }


import { chartsmodule } from 'ng2-charts';


   declarations: [yourcomponent],
   imports: [
export class modulewhereyourcomponentisdeclared { }


the reason might be: you are using ng2charts directly from your child components/module.

solutions: you have to import the ng2charts on your parent module as well. (import ng2charts [ng2-charts], to your parent and child module)

happy fixing everyone.

thank you. marjun villegas


i'm working with ng2-chart@3.0.0-rc.2

looks like the property charttype is now called type

so it should look something like this:

      style="display: block;background-color: #3a3939;" 


i'm working with ng2-charts + angular 7 + ionic 4, and i spent several hours searching for a solution. and this finally worked to me (after following the initial steps, of course, like installing ng2-charts and charts.js). just import chartsmodule on the following files:


import { chartsmodule } from 'ng2-charts';
imports: [chartsmodule]


import { chartsmodule } from 'ng2-charts';
  imports: [
    routermodule.forchild([{ path: '', component: yourpagepage }]),

i was trying to import it also in, but the solution was to import it in yourpage.module.ts!

try it out.


i had the very same problem. i found on github that you just have to insert the chartsmodule in the submodule as well. first you add in app.module.ts and the, in my case, reports.module.ts.

Related Query

More Query from same tag