【发布时间】:2018-10-12 11:41:46
【问题描述】:
我正在使用 Chart.js 插件来显示条形图,我得到的输出如下:
我的问题是,如何在将值渲染到栏后添加自定义文本?例如,In Jan,value 显示为 56。我想在其旁边添加 % increased/decrease 信息(即 56 [115 %]),该怎么做?
这是我的代码
window.chartHeadcount = new Chart(document.getElementById("barChartHeadcount"), {
type: 'bar',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
datasets: [{
label: 'Billed',
backgroundColor: 'rgb(0, 197, 106)',
data: billedHeadCount
}, {
label: 'Unbilled',
backgroundColor: 'rgb(255, 114, 107)',
data: unBilledHeadCount
}]
},
options: {
title: {
display: true,
text: 'Community Headcount - ' + Options.Globals.Year
},
tooltips: {
mode: 'index',
intersect: false
},
responsive: true,
scales: {
xAxes: [{
stacked: false
}],
yAxes: [{
stacked: false
}]
}
}
});
【问题讨论】: