Эй, я не знаю, поможет ли это вам, но я написал плагин для ChartJS , который делает именно то, что вы просите.Вы можете адаптировать исходный код в repo для своих собственных нужд.Вот соответствующий фрагмент:
/**
* 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();
}