gpt4 book ai didi

javascript - Chartjs 未显示所有数据点

转载 作者:行者123 更新时间:2023-11-28 17:32:08 25 4
gpt4 key购买 nike

我有一个包含 3 个点的数据集,但图表上只显示了两个点 Graph

创建该图的代码是

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Submission',
data: [{
t: new Date("April 1, 2018"),
y: 2
}, {
t: new Date("April 10, 2018"),
y: 1
}, {
t: new Date("April 27, 2018"),
y: 1
}],
backgroundColor: ["rgba(90, 150, 200, 0.6)"]
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});

显然有三个数据点,但图表上似乎只显示了 2 个。如何解决这个问题?

最佳答案

我通过为每个数据点添加标签来解决这个问题。 enter image description here

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["April 1, 2018", "April 10, 2018", "April 27, 2018", ],
datasets: [{
label: 'Submission',
data: [{
t: new Date("April 1, 2018"),
y: 2
}, {
t: new Date("April 10, 2018"),
y: 1
}, {
t: new Date("April 27, 2018"),
y: 1
}, {
t: new Date(),
y: 0
}],
backgroundColor: ["rgba(90, 150, 200, 0.6)"]
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});

关于javascript - Chartjs 未显示所有数据点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50078236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com