我试图在我的Angular 2应用程序中显示一个简单的高图,但它总是给我以下错误:
这是我的app.module.ts:
import { ChartModule } from 'angular2-highcharts';
@NgModule({
imports: [
ChartModule.forRoot('highcharts')
]
})
export class AppModule {
}
我的sistemjs.config.js:
map: {
'angular2-highcharts': 'npm:angular2-highcharts',
'highcharts': 'npm:highcharts'
},
packages: {
highcharts: {
main: './highcharts.js',
defaultExtension: 'js'
},
'angular2-highcharts': {
main: './index.js',
defaultExtension: 'js'
}
}
并且,在我的组件内:
import { Component } from '@angular/core';
import { ChartModule } from 'angular2-highcharts';
@Component({
selector: 'highchart',
template: '<chart [options]="options">'
})
constructor() {
this.options = {
title : { text : 'angular2-highcharts example' },
series: [{
name: 's1',
data: [2,3,5,8,13],
allowPointSelect: true
},{
name: 's2',
data: [-2,-3,-5,-8,-13],
allowPointSelect: true
}]
};
console.log(this.options);
}
options: Object;
有任何想法吗?非常感谢。
我几天前遇到过这个问题,在提到this thread之后,我找到了一个解决方案,这个配置现在适用于我:
//other important imports
import { ChartModule } from 'angular2-highcharts';
import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';
declare var require: any;
export function highchartsFactory() {
const hc = require('highcharts');
const hm = require('highcharts/highcharts-more');
const mr = require('highcharts/modules/solid-gauge');
mr(hc);
hm(hc);
return hc;
}
@NgModule({
declarations: [
//===== your declarations =====
],
imports: [
//your other imports goes here
ChartModule //------------> important import just chart module
],
providers: [{
provide: HighchartsStatic, //-----> and this too
useFactory: highchartsFactory
}],
bootstrap: [AppComponent]
})
export class AppModule { }