我有图表js bar的问题。这是选项:
trendChart = new Chart(ctx, {
type: 'bar',
data: {
labels: dynamicLabels,
datasets: [{
label: label1,
data: displayedDatas1,
borderColor: colors,
backgroundColor: colors,
fill: false,
borderWidth: 2
}]
},
options: {
showDatapoints: true,
tooltips: {
callbacks: {
label: function (tooltipItem, data) {
return data['datasets'][0]['data'][tooltipItem['index']] + ' %';
}
}
},
maintainAspectRatio: false,
legend: {
display: false
},
emptyOverlay: { // enabled by default
fillStyle: 'rgba(105,105,105,0.4)', // Change the color of the overlay to grey with a 40% alpha
fontColor: 'rgba(47,47,47,1.0)', // Change the text color to white
fontStroke: 'rgba(47,47,47,0)', // Change the text color to white
fontSize: $(window).width() > 1007 ? 25 : 15,
message: "Veuillez sélectionner vos activités et services, et choisissez une période",
fontStrokeWidth: 0 // Hide the stroke around the text
}
}
});
以及我如何更新数据:
trendChart.data.datasets[0] = {
label: label1,
data: displayedDatas1,
borderColor: colors,
backgroundColor: colors,
fill: false,
borderWidth: 2
};
trendChart.data.labels = dynamicLabels;
trendChart.update();
问题是,当我只有负数据时,条形图没有显示,但是当至少有一个正数据时它们会神奇地出现。
我已经尝试过:scaleBeginAtZero并在选项中打勾。
谢谢
尝试将scaleBeginAtZero: false
添加到您的options
对象。
scaleBeginAtZero: false
找到了!
问题是插件:chartjs-plugin-empty-overlay.js。禁用时,显示负值。应该已经阅读过doc,它只是测试了折线图。