Javascript 如何在chartjs中向下移动铭文垂直线
这里有一个绘制的图表,通过prototype.draw绘制一条垂直线。如果垂直线的文本超出画布且未显示,如何将其向下移动Javascript 如何在chartjs中向下移动铭文垂直线,javascript,canvas,charts,graphics,chart.js,Javascript,Canvas,Charts,Graphics,Chart.js,这里有一个绘制的图表,通过prototype.draw绘制一条垂直线。如果垂直线的文本超出画布且未显示,如何将其向下移动 Chart.elements.Line.prototype.draw = function () { this._chart.ctx.save(); this._chart.ctx.strokeStyle = '#808080'; var points = this._chart.getDatasetMeta(0).data, poi
Chart.elements.Line.prototype.draw = function () {
this._chart.ctx.save();
this._chart.ctx.strokeStyle = '#808080';
var points = this._chart.getDatasetMeta(0).data,
point_x = points[points.length - 1]._model.x,
point_y = points[points.length - 1]._model.y,
bottom = this._chart.scales['y-axis-0'].bottom;
this._chart.ctx.beginPath();
this._chart.ctx.lineWidth = 3;
this._chart.ctx.moveTo(point_x, point_y);
this._chart.ctx.lineTo(point_x, bottom);
this._chart.ctx.textAlign = 'right';
this._chart.ctx.fillStyle = '#808080';
if ($(window).width() < 420) {
this._chart.ctx.font = '500 14px "Montserrat", sans-serif';
this._chart.ctx.fillText("Payback", point_x - 2, bottom - 14);
} else {
this._chart.ctx.font = '500 16px "Montserrat", sans-serif';
this._chart.ctx.fillText("Payback", point_x - 5, bottom + 24);
}
this._chart.ctx.stroke();
this._chart.ctx.restore();
}
Chart.elements.Line.prototype.draw=函数(){
这是._chart.ctx.save();
这个._chart.ctx.strokeStyle='#808080';
var points=此._chart.getDatasetMeta(0).data,
点x=点[points.length-1]。\u model.x,
点y=点[points.length-1]。\u model.y,
底部=此。_图表比例['y轴-0']。底部;
这个._chart.ctx.beginPath();
这个._chart.ctx.lineWidth=3;
这个._chart.ctx.moveTo(点x,点y);
此._chart.ctx.lineTo(点x,底部);
这个._chart.ctx.textAlign='right';
这个._chart.ctx.fillStyle='#808080';
如果($(窗口).width()<420){
这个._chart.ctx.font='500 14px“蒙特塞拉特”,无衬线';
这个._chart.ctx.fillText(“回报”,第x-2点,底部-14点);
}否则{
这个._chart.ctx.font='500 16px“蒙特塞拉特”,无衬线';
这个._chart.ctx.fillText(“回报”,第x-5点,底部+24);
}
这个._chart.ctx.stroke();
这是._chart.ctx.restore();
}