1
I’m new here and this is my first question, I’m starting in PHP and wanted to know how to fill a CHART with variables received by an array.
My code sample is as follows::
<?php
$datacomp = date('d/m/y');
$consulta=mysql_query("SELECT SOBRECONSUMO_DIA, DATA_I FROM `atividades` WHERE SOBRECONSUMO = 1 and SOBRECONSUMO_DIA <> NULL");
$numrows=mysql_num_rows($consulta);
do {
$valor[$x]=$rows['SOBRECONSUMO_DIA'];
$data[$x]=$rows['DATA_I'];
echo "<script type=\"text/javascript\"> var x = '"$x"'var valor[x]='".$valor[$x]"' var data[x]='".$data[$x]"'}</script>";
} while ($rows= mysql_fetch_array($consulta))
And the JS code that will run after the above is this:
$(function () {
for (var i; x=i;i++)
{
Morris.Area({
element: 'morris-area-chart',
data: [{
period: data[x],
valor de consumo: valor[x],
}
]})
I know it’s wrong, but I need to know a way to run this loop to throw the dice to the Chart. Thanks!
Where do you traffic the data from
PHP
to page? You have to use ajax, you’ve heard of?– Marconi
I even read a few things about Ajax, I thought in that case I wouldn’t have to.
– VNSN
With where I deal you wonder where it comes from?
– VNSN
Yes, you need to transport them by Ajax and insert in the Chart.
– Marconi
would have some reference (link, code snippet) as an example for me to know how to do this?
– VNSN
I found this very interesting tutorial
– Marconi