ng2-charts的问题

时间:2017-04-20 17:35:15

标签: angular charts chart.js ng2-charts

我试图在角度2中向我的项目添加图表,但它无法找到chart.js文件。 那些是错误:

1. EXCEPTION: ng2-charts configuration issue: Embedding Chart.js lib is mandatory

2. Error: ng2-charts configuration issue: Embedding Chart.js lib is mandatory
    at BaseChartDirective.getChartBuilder (charts.js:70)
    at BaseChartDirective.refresh (charts.js:113)
    at BaseChartDirective.ngOnInit (charts.js:18)
    at _View_BarChartDetailComponent0.detectChangesInternal (BarChartDetailComponent.ngfactory.js:151)
    at _View_BarChartDetailComponent0.AppView.detectChanges (core.umd.js:12061)
    at _View_AdminPageStatusComponent0.AppView.detectViewChildrenChanges (core.umd.js:12087)
    at _View_AdminPageStatusComponent0.AppView.detectChangesInternal (core.umd.js:12072)
    at _View_AdminPageStatusComponent0.AppView.detectChanges (core.umd.js:12061)
    at _View_AdminPageStatusComponent_Host0.AppView.detectViewChildrenChanges (core.umd.js:12087)
    at _View_AdminPageStatusComponent_Host0.AppView.detectChangesInternal (core.umd.js:12072)

我将它添加到systemjs.config.js文件中:

map: {
    'ng2-charts': 'https://npmcdn.com/ng2-charts@1.4.0'
},
packages: {
    'ng2-charts': {
        main: 'ng2-charts.js',
        defaultExtension: 'js'
    }
}

我把它添加到index.js:

<script src="node_modules/chart.js/src/chart.js"></script>

并将其添加到app.module:

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

请帮我解决。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,将这样添加到 System.config.js

map: {
 'ng2-charts': 'npm:ng2-charts'
}

packages: {
'ng2-charts': {
      main: 'ng2-charts.js',
      defaultExtension: 'js'
 }
}

然后在你的模块中

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