我有一个mongo查询,用于在前端渲染数据。当我尝试使用它时,它在前端返回了[object Object],但我使用JSON.stringify对其进行了修复。
问题在于,现在我正确地获得了数据(我想),它无法呈现。
我有以下代码:
var ctx = document.getElementById('chartAt').getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [],
datasets: [{
label: 'Gráfico de atendimento',
<% for(var i=0; i<testatm.length; i++) { %>
data: [<%= JSON.stringify(testatm[i].sum) %>], // parâmetros do banco
<% } %>
backgroundColor: [
'rgb(71, 87, 112)',
'rgb(229, 226, 27)'
],
borderColor: [
'rgb(71, 87, 112)',
'rgb(229, 226, 27)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
}
我从Google开发人员控制台的“来源”标签上看到的是这样的:
标签:“ Garfico de atendimento”,
data: [5], // parâmetros do banco
data: [17], // parâmetros do banco
data: [35], // parâmetros do banco
data: [65], // parâmetros do banco
and it goes on...
但是我得到的图表很大,上面有2位数字,这很奇怪。
希望我能得到一些帮助,谢谢!