Chart.js-用鼠标在Angular 6中注释垂直线移动

时间:2018-11-05 12:30:00

标签: angular annotations chart.js angular6

如何使用鼠标Angular 6添加垂直线移动

canvas.onmousemove = function (evt) {
    var points = myChart.getElementsAtXAxis(evt);
    annotation.annotations[0].value = new Date(myChart.config.data.labels[points[0]._index]);
    myChart.update();

在角度版本上不起作用,如何动态更改注释值

我要移动此行enter image description here

1 个答案:

答案 0 :(得分:0)

canvas.onmousemove = (evt) => {

        docCountChart.update();

        var x = evt.pageX - canvas.offsetLeft - 30;

        context.beginPath();

        context.moveTo(x, 32);
        context.lineTo(x, 407);
        context.strokeStyle = 'gray';
        context.stroke();
        context.closePath();
    };