Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP、jQuery&;Js:将数据库中的实时数据显示到图表中_Php_Jquery_Ajax_Chartist.js - Fatal编程技术网

PHP、jQuery&;Js:将数据库中的实时数据显示到图表中

PHP、jQuery&;Js:将数据库中的实时数据显示到图表中,php,jquery,ajax,chartist.js,Php,Jquery,Ajax,Chartist.js,我正试图制作一个图表,在这个图表中我可以看到24小时内服务器的玩家数量。 我希望图表显示从00:00到晚上11:59,从30到30分钟。(00:30、1:00、1:30等) 我用来将数组发送到jQuery的代码 $json = array(); $stmt = $link->query("SELECT * FROM online WHERE time > $date"); $stmt->execute(); while($row = $stmt->fetch(PDO::

我正试图制作一个图表,在这个图表中我可以看到24小时内服务器的玩家数量。 我希望图表显示从00:00到晚上11:59,从30到30分钟。(00:30、1:00、1:30等)

我用来将数组发送到jQuery的代码

$json = array();
$stmt = $link->query("SELECT * FROM online WHERE time > $date");
$stmt->execute();

while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  $row['time'] = date("H:i", $row['time']); //translate unix to human
  array_push($json, array('labels' => $row['time'],
    'series' => $row['players']
    ));
}

echo json_encode(array("json" => $json));
输出:

这是我用来显示图表的jQuery

var url = "settings.php"
  var resp = jQuery.parseJSON(
    jQuery.ajax({
        url: url, 
        async: false,
        dataType: 'json'
       }).responseText
     );

    var JSONObject = JSON.parse(resp);

    var data = {"labels":JSONObject.labels, "series":[JSONObject.series]};


  optionsPlayersOnline = {
    lineSmooth: Chartist.Interpolation.cardinal({
      tension: 0
    }),
    low: 0,
    high: 50,
    chartPadding: {
      top: 0,
      right: 0,
      bottom: 0,
      left: 0
    },
  }

  var PlayersOnline = new Chartist.Line('.ct-chart', data, optionsPlayersOnline);
我的问题是我不知道如何使图表工作和显示