Chart that updates every n seconds

0

I'm using Google Charts and I need to make a chart that updates both the x-axis and the y-axis values every n seconds.

I need 50 data to be used for each update, so I used one SELECT max(id) FROM tabela_arduino to read the last value entered in the database. I tried to call this value in order to plot the chart, but the chart is not generated. Could anyone help solve this?

<?php

mysql_connect("localhost", "root", "") or
die("Não foi possível conectar: " . mysql_error());
mysql_select_db("banco_arduino");

$result = mysql_query("SELECT max(id) FROM tabela_arduino");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
   printf("ID: %s", $row["max(id)"]); 
}

echo  mysql_free_result($result);

$i=0;
$sql = "select * from tabela_arduino";
$resultado = mysql_query($sql);

?>


function desenharGrafico(){

    var dados=new google.visualization.DataTable();

    dados.addColumn('number', 'Registro');
    dados.addColumn('number', 'Talalla');

    dados.addRows(<?php echo $i ?>);

    <?php 
    $k = $i;

    //mudanças a partir  daqui
         $p = $row['max(id)'];

    for ($i = ($p-50); $i<$p; $i++){
    ?>
        dados.setValue(<?php echo $i ?>, 0, '<?php echo $id[$i] ?>');
        dados.setValue(<?php echo $i ?>, 1, <?php echo $sensor1[$i] ?>);

    <?php
    }
    ?>

    var options ={
        title: 'Gráfico ECG',
        width: 1280, height: 480,
        colors:['red'],
    legend: {position: 'bottom'}
    };

    var grafico = new google.visualization.LineChart(document.getElementById('curve_chart'));

    grafico.draw(dados, options);
};
    
asked by anonymous 18.04.2017 / 16:41

0 answers