score:5

Accepted answer

just add the following lines before you draw your line

...
this.clear();
this.draw();
...

by the way, your line doesn't stretch all the way to the bottom. if you want to make it stretch all the way down use 0 and this.chart.height for your ystart and yend. or you can use the y axis scale to calculate the max and min pixels for the scale (see https://jsfiddle.net/ombaww9t/).


fiddle - https://jsfiddle.net/56s9av1j/

score:5

working version for 2.6.0 (change 'y-axis-0' to the id of you y-axis)

// hook into main event handler
let parenteventhandler = chart.controller.prototype.eventhandler;
chart.controller.prototype.eventhandler = function () {
    let ret = parenteventhandler.apply(this, arguments);

    let x = arguments[0].x;
    let y = arguments[0].y;
    this.clear();
    this.draw();
    let yscale = this.scales['y-axis-0'];
    this.chart.ctx.beginpath();
    this.chart.ctx.moveto(x, yscale.getpixelforvalue(yscale.max));
    this.chart.ctx.strokestyle = "#ff0000";
    this.chart.ctx.lineto(x, yscale.getpixelforvalue(yscale.min));
    this.chart.ctx.stroke();

    return ret;
};

Related Query

More Query from same tag