score:0

hey i don't know if this still helps you, but i wrote a plugin for chartjs which does exactly what you're asking. you may be able to adapt the source code in the repo for your own needs. here's a relevant snippet:

  /**
   * draw the line height annotation to the highest data point on the chart.
   * @param {int} x horizontal coordinate on canvas
   * @param {int} bottomy bottom y dimension of the chart
   * @param {float} highestdatay highest possible y value on the chart, taking padding and border offsets into consideration.
   */
  drawlineheightannotation(x, bottomy, highestdatay) {
    let ctx = this.ctx;
    let options = this.options;

    ctx.save();
    ctx.beginpath();
    if (!options.nodash) {
      ctx.setlinedash([10, 10]);
    }
    ctx.moveto(x, highestdatay);
    ctx.lineto(x, bottomy);
    ctx.linewidth = options.lineweight ? options.lineweight : 1.5;
    ctx.strokestyle = options.color ? options.color : "#000";
    ctx.stroke();
    ctx.restore();
  }

Related Query

More Query from same tag