小编iLu*_*uPa的帖子

将JSON数据输出到Chart.js标签和数据

我想使用Chart.js查询MySQL数据库获取数据,将JSON数据输出到Chart .

基本上我要查询的是(data.php):

<?php

header('Content-Type: application/json');

$con = //Database connection

// Check connection
if (mysqli_connect_errno($con))
{
    echo "Failed to connect to DataBase: " . mysqli_connect_error();
}
else
{
    $data_points = array();
    $result = mysqli_query($con, "SELECT * FROM condicao order by id desc limit 10");

    while($row = mysqli_fetch_array($result))
    {        
        $point = array($row['timestamp'], $row['temperatura']);
        array_push($data_points, $point);        
    }

    echo json_encode($data_points, JSON_NUMERIC_CHECK);

}

mysqli_close($con);

?>
Run Code Online (Sandbox Code Playgroud)

这给了我以下数组(timestamp,temperature):

[
    ["2014-08-04 23:06:01",16.9],
    ["2014-08-04 23:03:02",17.1],
    ["2014-08-04 23:00:02",17.1],
    ["2014-08-04 22:57:01",17.1],
    ["2014-08-04 22:54:01",17.1],
    ["2014-08-04 …
Run Code Online (Sandbox Code Playgroud)

javascript php jquery charts

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

charts ×1

javascript ×1

jquery ×1

php ×1