Chartjs-How can I draw lines inside the bars in charts.js?

0👍

Chart.pluginService.register({
    afterDraw: function(chart) {
        var ctx = chart.ctx;

        chart.config.data.datasets.forEach(function (dataset) {
            for (var i = 0; i < dataset.data.length; i++) {
                var yAxe = chart.scales[chart.config.options.scales.yAxes[0].id];
                ctx.strokeStyle = "red";
                ctx.beginPath();
                ctx.setLineDash([10, 10]);
                //value
                lineAt = yAxe.getPixelForValue(200);

                var model = dataset._meta[Object.keys(dataset._meta)[0]].data[i]._model;

                ctx.moveTo(model.x - (model.width / 2), lineAt);
                ctx.lineTo(model.x + (model.width / 2), lineAt);
                ctx.stroke();
            }
        });
    }
});

Leave a comment