Chartjs-Error says Chart is not defined

1👍

You need to import the Chart class from an import clause:

import {Chart} from 'chartjs';

The something depends on the way you configured SystemJS.

The typings you include is only used for compilation and autocompletion within your IDE.

Edit

The corresponding SystemJS configuration for the chartjs library is:

System.config({
  map: {
    chartjs: 'node_modules/chartjs/chart.js'
  },
  (...)
});

See this plunkr: https://plnkr.co/edit/IA2LojT2CXV9qcCDOdBl?p=preview.

Edit2

Regarding typings, I would install the corresponding one this way:

  • Install the library typings from npm

    npm install --save-dev retyped-chartjs-tsd-ambient
    
  • Importing the typings using typings

    typings install --save --ambient file:node_modules/retyped-chartjs-tsd-ambient/chart.d.ts
    
  • There is still an error since the d.ts file doesn’t declare a module name. To fix that you can wrap the declaration of this file with a declare module clause:

    declare module 'chartjs' {
      interface ChartDataSet {
        label: string;
      (...)
    }
    

Leave a comment