使用Highcharts与MySQL数据库中的数据的动态图表

时间:2016-05-25 10:17:23

标签: javascript php mysql highcharts

我试图根据本教程https://www.youtube.com/watch?v=9zxfoamp-xc制作包含MySQL数据库更新数据的动态图表,但屏幕上没有任何内容。没有图表生成。

datos.php

id="submitbutton"

json输出

[{" X":" 0"" Y":" 2"},{" X&#34 ;:" 5"" Y":" 3"},{" X":" 10",& #34; Y":" 3"},{" X":" 15"" Y":" 3"},{" X":" 20"" Y":" 4"},{" X& #34;:" 30"" Y":" 3"},{" X":" 35" " Y":" 5"},{" X":" 40"" Y":&# 34; 4"},{" X":" 45"" Y":" 3"}]

的index.html

<?php
$pdo=new PDO("mysql:dbname=basededatoslocal;host=127.0.0.1","root","");

if(isset($_GET['Consultar']) && $_GET['Consultar']=='1'){
            $statement=$pdo->prepare("SELECT valorx as x, valory as y FROM medidas ORDER BY id DESC LIMIT 0,1");
            $statement->execute();
            $results=$statement->fetchAll(PDO::FETCH_ASSOC);
            $json=json_encode($results);
            echo $json;
}
else
{
        // Buscar Todos los datos

            $statement=$pdo->prepare("SELECT valorx as x, valory as y FROM medidas ORDER BY id ASC");
            $statement->execute();
            $results=$statement->fetchAll(PDO::FETCH_ASSOC);
            $json=json_encode($results);

            echo $json;
}


?>

我希望有人可以帮助我。

谢谢,保罗

1 个答案:

答案 0 :(得分:1)

本教程的作者帮助了我。我只发布datos.php工作代码,因为上一篇文章中的index.html没问题。也许它有助于某人:)

<?php
error_reporting(0);
header('Content-Type: application/json');
$pdo=new PDO("mysql:dbname=basededatoslocal;host=127.0.0.1","root","");
switch($_GET['Consultar']){
        // Buscar Último Dato
        case 1:
            $statement=$pdo->prepare("SELECT valorx as x, valory as y FROM medidas ORDER BY id DESC LIMIT 0,1");
            $statement->execute();
            $results=$statement->fetchAll(PDO::FETCH_ASSOC);
            $json=json_encode($results);
            echo $json;
        break; 
        // Buscar Todos los datos
        default:

            $statement=$pdo->prepare("SELECT valorx as x, valory as y FROM medidas ORDER BY id ASC");
            $statement->execute();
            $results=$statement->fetchAll(PDO::FETCH_ASSOC);
            $json=json_encode($results);
            echo $json;
        break;
}
?>