Can't find module 'chart.js'.) Angular 2
Hi I am using the Angular2 CLI and am trying to import the chart.js module but every time I start the server I get " cannot find the" chart.js "module
import { Component } from '@angular/core';
import Chart from 'chart.js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
title = 'Test';
let myChart = new Chart({});
};
+3
source to share
3 answers
It looks like you have specified your chart import incorrectly
You have:
import Chart from 'chart.js';
But it should be:
import { Chart } from 'chart.js';
Also make sure you have the chart.js npm package installed, if you didn't install it correctly, you can install it with:
npm install chart.js --save
0
source to share
You can try ng2-charts or another Angular2 chart.js library to set this. This makes it much easier to import and use. From the README ...
import { ChartsModule } from 'ng2-charts/ng2-charts';
// In your App module:
imports: [
ChartsModule
]
-1
source to share