我正在使用以下数据集,
this.chart = new Chart(
this.canvasContext,
{
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]
}
]
},
options: {
showScale: true,
maintainAspectRatio: false,
responsive: true,
utoutPercentage: 50,
animation: {
animateRotate: true,
duration: 2000,
animateScale: true
}
}
}
)所有列都出现了。
但是如果我使用data: [600,400,400,900,1100],400值不会出现在图表上。它们以零的形式出现。

我正在使用canvas width和height <canvas id="myChart" width="400" height="400"></canvas>
有什么问题吗?
发布于 2020-03-03 15:08:16
发布于 2020-03-03 15:38:02
解决方案如下:
this.chart = new Chart(
this.canvasContext,
{
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [2478,5267,734,784,433]
}
]
},
options: {
showScale: true,
maintainAspectRatio: false,
responsive: true,
utoutPercentage: 50,
animation: {
animateRotate: true,
duration: 2000,
animateScale: true
},
scales: {
xAxes: [
{
stacked: true
}
],
yAxes: [
{
stacked: true
}
]
}
}
}
)只需添加一个关于缩放x和y轴的选项即可。
https://stackoverflow.com/questions/60501625
复制相似问题