我需要帮助将饼图的编号放入图例中
图表图像 https://i.stack.imgur.com/grBpc.png
如果我用鼠标悬停图表,我可以看到相对于每个项目的数字
我想将它显示在图例中
到目前为止的重要代码:
var tempData = {
labels: Status,
datasets: [
{
label: "Status",
data: Qtd,
backgroundColor: randColor
},
]
};
var ctx = $("#pieStatus").get(0).getContext("2d");
var chartInstance = new Chart(ctx, {
type: 'pie',
data: tempData,
options: {
title: {
display: true,
fontsize: 14,
text: 'Total de Pedidos por Situação'
},
legend: {
display: true,
position: 'bottom',
},
responsive: false
}
});
“Qtd”,“randColor”是“var”已经有值
您需要编辑generateLabels
您的选择中的财产:
options: {
legend: {
labels: {
generateLabels: function(chart) {
// Here
}
}
}
}
Since it is quite a mess to create on your own a great template. I suggest using the same function as in
the source code https://github.com/chartjs/Chart.js/blob/master/src/controllers/controller.doughnut.js#L42-L69 and then edit what is needed.
这里有一个小jsFiddle https://jsfiddle.net/6bexkyd9/,您可以在其中查看它是如何工作的(已编辑的行 - 从 38 行开始 - 已注释),及其结果:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)