Как сдвинуть вертикальную линию надписи вниз в chartjs - PullRequest
1 голос
/ 01 апреля 2019

Существует построенный график chartjs, и через prototype.draw рисуется вертикальная линия. Как переместить текст вертикальных линий вниз, если он выходит за пределы холста и не отображается?

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();
}

просмотр диаграммы

потребность

...