【发布时间】:2020-09-08 11:18:26
【问题描述】:
如何在 ChartJs 函数的 onClick 函数上获取角度 component?有办法吗?因为this 是图表,self 是窗口...
我的图表就是这样添加到some.component.ts
@ViewChild(Chart) mainChart: Chart // declaration on public variables on component.ts
// construction of chart on API call result
this.mainChart = new Chart(MeasureUnitMonthlyComponent.CHART_ID, {
type: 'bar',
data: {
labels: aChartLabelsArray,
datasets: aDatasetsArray
},
options: {
onClick: this.onChartClicked,
legend: {
display: true
},
....
【问题讨论】:
-
TS 看起来不像 Angular 组件;将该图表定义为
@ViewChild... 然后它有一个父组件。 -
@MartinZeitler thx,已更新但仍不知道如何获取它。更新了截图
标签: javascript angular chart.js