如何在chartjs中显示每个条形图顶部的条形值



我正在使用Chartjs绘制一些条形图,我想在每个条形图的顶部显示相关值,我在文档中没有看到任何允许这样做的参数。

有办法做到这一点吗?

您可以尝试

    onAnimationComplete: function () {    
        var ctx = this.chart.ctx;
        ctx.font = this.scale.font;
        ctx.fillStyle = this.scale.textColor
        ctx.textAlign = "center";
        ctx.textBaseline = "bottom";
        this.datasets.forEach(function (dataset) {
            dataset.bars.forEach(function (bar) {
                ctx.fillText(bar.value, bar.x, bar.y - 5);
            });
        })
    }

使用下列链接

http://jsfiddle.net/TZq6q/304/

在代码中设置"inGraphDataShow:true",它将在条顶部显示所有值

最新更新