查看图表之外的Chart.js工具提示数据

时间:2019-08-07 11:01:03

标签: javascript angular chart.js

我正在使用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'
    }

0 个答案:

没有答案
相关问题