您可能正在使用 angular 2 RC。 mharrington 的回答是关于 ionic beta.37(我猜),它使用了 angular 2 的 beta 版本。
现在更新为ChartModule。见下文或查看github 和他们的demo (plnkr)
正如 angular2-highcharts 所解释的:
在您的@ngModule 声明文件中(可能是app.module.ts)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ChartModule } from 'angular2-highcharts';
import { App } from './App';
@NgModule({
imports: [BrowserModule, ChartModule],
declarations: [App],
bootstrap: [App]
})
export class AppModule {}
在你的班级里:
import { Component } from '@angular/core';
@Component({
selector: 'simple-chart-example',
template: `
<chart [options]="options"></chart>
`
})
export class App {
constructor() {
this.options = {
title : { text : 'simple chart' },
series: [{
data: [29.9, 71.5, 106.4, 129.2],
}]
};
}
options: HighchartsOptions;
}
另外,根据您使用的版本,您可能需要更改导入来源
import { ChartModule } from 'ng2-charts';
到
import { ChartModule } from 'ng2-charts/components/charts/charts';
因为this issue (#440)
请记住,文档可能已过时,具体取决于版本,如果绑定到 [datasets] 失败,请绑定到 [data] 来源:ng2-charts - Can't bind to 'datasets' since it isn't a known property of 'base-chart'