0

I need make a graph in highcharts, but I need to get the values from mysql until now I only can add the timestamp value, but still left the other value to the Y graph, Im new in all this I hope you can give some help, the other value I need to use is a int value.

I'm still trying to add the second value, but with this only value (hour) shows me nothing.

The homework is to make a graph with values in function of time

<HTML>
    <head>
        <!-- Importa las librerias de jQuery y las de Highcharts -->
        <script type="text/javascript" src="https://code.jquery.com/jquery.js"></script>
        <script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
        <script type="text/javascript" src="http://code.highcharts.com/modules/exporting.js"></script>
    </head>
    <body>
        <?php
            $conexion = mysql_connect('localhost','root' , '') or trigger_error(mysql_error(),E_USER_ERROR);
            mysql_select_db('fancysensorsdb', $conexion);
            $query = "SELECT hora FROM temperatura";
            $registros = mysql_query($query) or die(mysql_error());
            while ($datos = mysql_fetch_array($registros)) 
            {
                extract ($datos);
                $datetime *= 1000; // Convertir hora Unix a JavaScript
                $data[] = "[$datetime, $hora]";
            }

            $query = "SELECT valor FROM temperatura";
            $registros = mysql_query($query) or die(mysql_error());
            while ($valores = mysql_fetch_array($registros)) 
            {
                extract ($valores);
                $datos[] = $valores;
            }
        ?>
        <script type="text/javascript">
            var chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container'
                },
                series: [{
                    data: [<?php echo join($data, ',') ?>]
                }]
            });
        </script>

        <div id="container" style="width: 100%; height: 500px; margin: 0 auto"></div>
    </body>
</html>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

1 Answers1

0

Basically you are passing variable data from PHP to javaScript. Based on your code, it won't work. Please take a look at this post.

Community
  • 1
  • 1
juntapao
  • 407
  • 3
  • 12