小编sim*_*mon的帖子

如何在 HighCharts 回调(Angular / Typescript)中访问“this”的不同上下文

我在 Angular/Typescript 项目中使用 HighCharts。通常它工作正常,但现在我卡住了:

单击某个点时,我想从 http 服务中获取有关该点的更多信息。HighCharts 提供了添加回调函数的可能性:http ://api.highcharts.com/highstock/plotOptions.series.point.events.click

问题是我需要关于点的信息(点信息绑定到“this”),但还需要调用服务,其中“this”指的是类实例。

@Component({
    // ...
})
export class ChartComponent {

    chart: any;

    constructor(private dataService: DataService) {    }

    onPointClick(point: any) {
        this.dataService.getPointDetails(point) // then ...
    }

    buildDataChart() {
        let Highcharts = require('highcharts/highstock');
        this.chart = new Highcharts.StockChart({
            // ...
            plotOptions: {
                series: {
                    point: {
                        events: {
                            click: // How to implement this function?
                        }
                    }
                }
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的事情但没有成功:

click: function() {
    console.log('Point information ' + this.x + ' ' …
Run Code Online (Sandbox Code Playgroud)

javascript callback highcharts typescript angular

4
推荐指数
1
解决办法
1892
查看次数

标签 统计

angular ×1

callback ×1

highcharts ×1

javascript ×1

typescript ×1