score:4

Accepted answer

you can fix the problem with an update to chart.js 2.9.3 and passing an empty hover function:

<html>
<head>

</head>
<body>
<canvas id="container"></canvas>
<script src="https://pagecdn.io/lib/chart/2.9.3/chart.bundle.min.js"></script>
</body>
</html>
let barchartdata = {
    labels:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
    datasets: [{
        label: 'sessions',
        backgroundcolor: 'rgba(0,163,224, 0.7)',
        bordercolor: 'rgba(0,163,224, 1)',
        borderwidth: 1,
        data:[81, 69, 60, 51, 37, 35, 45, 65, 86, 58, 64, 39, 48, 29, 69, 80, 52, 61, 56, 40, 51, 31, 70, 51, 32, 51, 27, 30, 44, 59, 46]
    }]
};
const id = 'container';
let ctx = document.getelementbyid(id).getcontext("2d");
let chart = new chart(ctx, {
    type: 'bar',
    data: barchartdata,
    options: {
        responsive: true,
        "animation": {
            "duration": 1,
            "oncomplete": function () {
                let chartinstance = this.chart, ctx = chartinstance.ctx;
                ctx.font = chart.helpers.fontstring(chart.defaults.global.defaultfontsize, chart.defaults.global.defaultfontstyle, chart.defaults.global.defaultfontfamily);
                ctx.textalign = 'center';
                ctx.textbaseline = 'bottom';
                ctx.fontcolor = 'black'
                this.data.datasets.foreach(function (dataset, i) {
                    let meta = chartinstance.controller.getdatasetmeta(i);
                    meta.data.foreach(function (bar, index) {
                        let data = dataset.data[index];
                        ctx.filltext(data, bar._model.x, bar._model.y - 5);
                    });
                });
            }
        },
        hover: () => {},
        plugins: {
            datalabels: {
                color: '#000000'
            }
        },
        legend: {
            display: false
        },
        tooltips: {
            enabled: true,
            mode: 'label'
        },
    }
});

this fix doesn't work with chart.js 2.7.3. i don't know if it's a bug or a different behavior on purpose.

live example


Related Query

More Query from same tag