我的问题是从mysql数据库中获取数据后,我可以将数据传递到前端,但是即使我尝试了许多解决方案,也无法在js图表图形中使用这些数据。谁能给我分享链接或提供有关该问题的示例?
chartdesign.js
new Chart(document.getElementById("myChart"), {
type: 'bar',
data: {
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"],
datasets: [
{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"],
data: [] // I want to add data here
}
]
},
options: {
legend: { display: false },
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
}
});
graphPage.hbs
<div class="card-group" style="margin-top: 50px; margin-bottom: 50px;">
<!-- Graphs -->
<div class="card-columns" style="margin-top:50px;">
<div class="card border-light" data-placement="top" style=" background-color:white;">
<div class="card-body">
<canvas id="myChart" width="400" height="300"></canvas>
</div>
</div>
</div>
app.js
config.query('//select query part',(err,ornek)=>{
if(err){
res.send('/404.html');
}
else{
req.session.ornek= ornek;
res.render('graphPage',{user: req.session.fullname, ornek: req.session.ornek});
}
});