Stacked horizontal bar chart along total count with chart.js

萝らか妹 提交于 2020-02-24 11:17:40

问题


I am unable to find the solution to add the total count for Stacked horizontal bar chart !

codepen link: code link enter code here


回答1:


You can use the following code to draw/add total count in your stacked horizontal bar chart :

this.data.datasets[0].data.forEach(function(data, index) {
   var total = data + this.data.datasets[1].data[index];
   var meta = chartInstance.controller.getDatasetMeta(1);
   var posX = meta.data[index]._model.x;
   var posY = meta.data[index]._model.y;
   ctx.fillStyle = 'black';
   ctx.fillText(total, posX + 4, posY + 4);
}, this);

add this inside chart­'s animation onComplete function.

ʟɪᴠᴇ ᴅᴇᴍᴏ



来源:https://stackoverflow.com/questions/46260551/stacked-horizontal-bar-chart-along-total-count-with-chart-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!