5
Well personal I have a database query that returns an array of data. and wanted to put the values to be displayed on the chart in Bars. I tried this but with values coming from vector the graph does not load.
while ($estoque = $estoques->fetch_assoc()) {?>
<?$semana[$i]=$estoque['week'];
$valor[$i]=$estoque['quant'];
);
}
$i=$semana[$i];
print"<script>alert('$i')</script>";
?>
<canvas id="GraficoBarra" style="width:50%;"></canvas>
<script type="text/javascript">
var options = {
responsive:true
};
var data = {
labels: [<?print $semana[1];?>, <?print $semana[2];?>,<?print $semana[3];?>, <?print $semana[4];?>, <?print $semana[5];?>, <?print $semana[6];?>, <?print $semana[7];?>, <?print $semana[8];?>],
datasets: [
{
label: "Dados secundários",
fillColor: "rgba(151,187,205,0.5)",
strokeColor: "rgba(151,187,205,0.8)",
highlightFill: "rgba(151,187,205,0.75)",
highlightStroke: "rgba(151,187,205,1)",
labels: [<?print $valor[1];?>, <?print $valor[2];?>,<?print $valor[3];?>, <?print $valor[4];?>, <?print $valor[5];?>, <?print $valor[6];?>, <?print $valor[7];?>, <?print $valor[8];?>]
}
]
};
window.onload = function(){
var ctx = document.getElementById("GraficoBarra").getContext("2d");
var BarChart = new Chart(ctx).Bar(data, options);
}
</script>
Dude, I think I better do this by ajax instead of trying to load this way.
– Diego Souza
I don’t have enough knowledge in Ajax.
– Ricardo Miranda
If you are using PHP you could simply generate the image already with GD. The more layer you place, the more complex it becomes, with no benefit. By the way, even with HTML+CSS you generate beautiful graphics today, and without losing the semantics.
– Bacco
Can edit the question by placing exactly what the array renders in a new block?
– Felipe Assunção