1
Good evening, I have the following model:
var mongoose = require('mongoose');
module.exports = function() {
var schema = mongoose.Schema({
nome: {
type: String,
required: true
},
valor: {
type: Number,
required: true
}
return mongoose.model('Contato', schema);
};
I need to create a simple pie chart, showing the values of the Contact model.value.
I imported Chartjs into my html:
<script src="Chart.min.js"></script>
In my body, I tried to add the chart:
<div class="box-chart">
<canvas id="GraficoPizza" style="width:100%;"></canvas>
<script type="text/javascript">
var options = {
responsive:true
};
var data = [
{
**value: Contato.valor(),**
**color:"#F7464A",**
**highlight: "#FF5A5E",**
**label: "Contato.nome"**
},
]
window.onload = function(){
var ctx = document.getElementById("GraficoPizza").getContext("2d");
var PizzaChart = new Chart(ctx).Pie(data, options);
}
</script>
My question is in passing parameters of the variable date, I need a way to go through all contacts, picking its value and generating a random color.