【发布时间】:2019-10-18 14:23:33
【问题描述】:
我在将数据从 Firestore 数据绘制到 ChartJS 时遇到问题。出于某种原因,它仅在图表底部显示单个值,并在 y 轴上显示随机数而不是日期。我希望有一个人可以帮助我。 我的火库:firestore 我的图表:chart
这是我目前所拥有的。
db.collection('Items').get().then((snapshot) => {
snapshot.docs.forEach(doc => {
var item= doc.data();
var price= item.price;
var date = item.date;
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [date],
datasets: [{
label: 'Items',
data: [price],
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
},
// Container for pan options
pan: {
// Boolean to enable panning
enabled: true,
// Panning directions.
mode: 'x',
speed: 1
},
// Container for zoom options
zoom: {
// enable zooming
enabled: true,
// Zooming directions.
mode: 'x',
}
}
});
})
})
【问题讨论】:
标签: javascript html firebase google-cloud-firestore chart.js