angular2-highcharts错误:“图表是未知的图表类型”

问题描述 投票:2回答:1

我试图在我的Angular 2应用程序中显示一个简单的高图,但它总是给我以下错误:

enter image description here

这是我的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;

有任何想法吗?非常感谢。

angular highcharts gauge angular2-highcharts
1个回答
3
投票

我几天前遇到过这个问题,在提到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 { }
© www.soinside.com 2019 - 2024. All rights reserved.