我正在尝试实现highcharts-angular
( https://github.com/highcharts/highcharts-angular)在我的角度申请并得到以下错误
( https://github.com/highcharts/highcharts-angular)在我的角度申请并得到以下错误
Cannot read property 'chart' of undefined at HighchartsChartComponent.updateOrCreateChart (highcharts-chart.component.ts:35)
我想使用bellcurve模块,但我无法使用它.
我试图使用stackblitz重新创建我的问题
请参阅https://stackblitz.com/edit/angular-unf7pz
不确定是什么问题
解决方法
通过使用
https://github.com/highcharts/highcharts-angular
它很容易理解,但是从你的stackblitz中有一些你没有遵循的指令:
1 /在共享/ Highcharts / bellcurve / bellcurve-chart.component中你需要绑定Highcharts:
HTML:
<highcharts-chart [Highcharts]="Highcharts" --> ITS required [options]="options" --> ITS required
TS:
import * as Highcharts from 'highcharts'; ... export class BellCurveChartComponent implements OnInit { Highcharts = Highcharts; options = {title: ...,xAxis: ...}; ... }
阅读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);
3 /如果要使用图表实例,请使用回调函数callbackFunction
HTML:
[callbackFunction]="getInstance.bind(this)"
TS:
getInstance(chart): void { // chart instance this.chart = chart; }
那就是,检查一下工作代码: