我对图表 js 栏有疑问。 以下是选项:
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
关于javascript - 图表 js 仅在积极数据时显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53264138/