我正在使用Chart.js制作堆积条形图,其中(总堆积)值范围从0到1(显示为0-100%) . 我希望每0.20 / 20%显示一个勾选/网格线,从0到包括1/100% .
现在,如果我不包含图表 Headers ,我的图表将以1/100%显示最后一个网格线,但如果我显示 Headers ,则会隐藏网格线(但仍然有刻度标签) .
有关网格线显示的提示吗?
JS在这里小提琴:https://jsfiddle.net/amyzlc/n99xac76/,以及下面的相关图形代码 .
链接到图表的图像与 Headers 和没有顶部网格here .
var stackedBar = new Chart(ctx, {
type: 'bar',
data: dataChart,
options: {
title: {
display: true, //top gridline displays if false, not if true
text: 'Month-wise Adherence'
},
legend: {
position: 'bottom'
},
scales: {
xAxes: [{
stacked: true,
gridLines: {display: false}
}],
yAxes: [{
stacked: true,
gridLines: {drawBorder: false, tickMarkLength: 3},
ticks: {
min: 0,
max: 1, //not showing with title
padding: 6,
stepSize: 0.2,
callback: function(value) {
return Math.round(value*100).toString() + "%";
}
}
}]
}
}
});
谢谢!