我正在使用Angular 8.X和Chart.js。我有一个显示在html中的数字-像这样:
<h1>{{ val }}</h1>
。
在该数字下面,我显示一个chart.js折线图。
将鼠标悬停在图表上时,我想根据图表中的值更改该数字。它不应该是工具提示。
我查看了Chart.JS文档,但没有找到任何用于访问Chart(this.ctx, { ... })
之外的数据的东西。
我的代码大致如下:
this.val = 10;
this.chartHours = new Chart(this.ctx, { ... } );
// change val while hovering over the chart
更新
我用以下方法解决了它:
Chart.Tooltip.positioners.custom = function(elements, position) {
return {
x: position.x,
y: -18,
}
}
和
tooltips: {
position:'custom'
}