Chart.js Chartjs列不按值显示
我正在使用以下数据集Chart.js Chartjs列不按值显示,chart.js,Chart.js,我正在使用以下数据集 this.chart = new Chart( this.canvasContext, { type: 'bar', data: { labels: ["Africa", "Asia", "Europe", "Latin America", "North America"], datasets: [ { label: "Population (millio
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
}
}
}
)
所有列都将出现
但如果我使用数据:[6004004009001100]
,400个值不会出现在图表上。它们显示为零
我正在使用画布的宽度和高度
问题出在哪里?检查此沙箱:
它确实有效。可能正在尝试清除缓存,然后尝试检查此沙盒:
它确实有效。可以尝试清除缓存,然后在此处尝试解决方案:
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轴的选项。解决方案:
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轴的选项。我更新了您的沙盒
,出现了相同的问题。添加此缩放:{yAxes:[{stacked:true}}}作为额外选项。因为它在这个研究中画了y轴,如果我有2个数据集,同样的问题会出现。@barteloma你会在提供的沙盒链接中复制你的问题吗让我们看看。我更新了你的沙盒
,同样的问题出现了。添加这个比例:{yAxes:[{stacked:true}}}作为一个额外选项。因为它在这个研究中画了y轴,如果我有2个数据集,同样的问题也会出现。@barteloma,你能在提供的沙盒链接中复制你的问题吗?让我们来看看。我不知道这种情况的最佳原因,但我想,如果我有2个数据集,在这个研究中设置画布样式的宽度和高度时,可能不是出于任何原因,而是一个小错误,同样的问题出现了。@barteloma你能在codesanbox上分享吗?我们可以为您的问题找到答案我不知道这种情况的最佳原因,但我认为这可能是一个小错误,没有任何原因,当您在本研究中设置画布样式的宽度和高度时,如果我有2个数据集,则会出现相同的问题。@barteloma您可以在codesanbox上共享它吗?我们可以找到你问题的答案