我在我的angular应用程序中使用highcharts的angular-highcharts实现。在这里,我举了一个例子
chart = new Chart({
chart: {
type: 'spline',
events: {
click: (e) => {
this.getCategory(this.chart.ref.series[0].searchPoint(e, true).category);
}
}
},
title: {
text: 'Monthly Average Temperature'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature'
}
},
tooltip: {
crosshairs: true,
shared: true
},
plotOptions: {
spline: {
marker: {
radius: 4,
lineColor: '#666666',
lineWidth: 1
}
}
},
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}]
})如果您查看chart对象中的chart属性
chart: {
type: 'spline',
events: {
click: (e) => {
this.getCategory(this.chart.ref.series[0].searchPoint(e, true).category);
}
}
}我正在将一个单击事件绑定到我的组件中的getCategory(category : any)方法。
现在的问题是,当我调用this.chart.ref.series[0].searchPoint(e,true)时,它在集成开发环境中给出错误“属性'searchPoint()‘在类型'chart’上不存在”,但当我在web浏览器中运行它时出现这个错误,它工作得很好。当角度视图完全加载时,chart对象中存在searchPoint()方法。
现在,如何从组件中删除这个错误“属性不存在”。我尝试使用括号表示法,但这对我不起作用。
发布于 2018-06-13 20:20:01
为什么不用"ngAfterViewInIt“来写事件呢?
如果使用此生命周期方法,它将在组件视图完全加载后加载
https://stackoverflow.com/questions/50836442
复制相似问题