highcharts-angular:无法读取未定义的属性"图表"

Tom*_*Tom 6 highcharts angular

我试图在我的角度应用程序中实现highcharts-angular(https://github.com/highcharts/highcharts-angular)并得到以下错误

Cannot read property 'chart' of undefined
at HighchartsChartComponent.updateOrCreateChart (highcharts-chart.component.ts:35)
Run Code Online (Sandbox Code Playgroud)

我想使用bellcurve模块,但我无法使用它.

我试图使用stackblitz重新创建我的问题

请参阅https://stackblitz.com/edit/angular-unf7pz

不确定是什么问题

Fet*_*rij 10


使用https://github.com/highcharts/highcharts-angular


它很容易理解,但是从你的stackblitz中有一些你没有遵循的指令:

1/shared/Highcharts/bellcurve/bellcurve-chart.component你需要绑定Highcharts:Html:

<highcharts-chart 
  [Highcharts]="Highcharts" --> ITS REQUIRED
  [options]="options"       --> ITS REQUIRED
Run Code Online (Sandbox Code Playgroud)

TS:

import * as Highcharts from 'highcharts';
...
export class BellCurveChartComponent implements OnInit {
    Highcharts = Highcharts;
    options = {title: ..., xAxis: ...};
    ...
}
Run Code Online (Sandbox Code Playgroud)

阅读https://github.com/highcharts/highcharts-angular#general-prerequisites

2 /您需要按照https://github.com/highcharts/highcharts-angular#to-load-a-module中的步骤加载要使用的正确模块(钟形曲线)

import bc from 'highcharts/modules/histogram-bellcurve.js';
bc(Highcharts);
Run Code Online (Sandbox Code Playgroud)

3 /如果要使用图表实例,请使用回调函数 callbackFunction

HTML:

 [callbackFunction]="getInstance.bind(this)"
Run Code Online (Sandbox Code Playgroud)

TS:

 getInstance(chart): void {
    // chart instance
    this.chart = chart;
 }
Run Code Online (Sandbox Code Playgroud)

那就是,检查一下工作代码:

https://stackblitz.com/edit/angular-k85q94