我在 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)