Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
Javascript 将数据插入Flot_Javascript_Jquery_Mysql_Ajax_Flot - Fatal编程技术网

Javascript 将数据插入Flot

Javascript 将数据插入Flot,javascript,jquery,mysql,ajax,flot,Javascript,Jquery,Mysql,Ajax,Flot,我很难在Flot图上显示数据数组。我正在使用jQueryAjax/PHP/MySQL来实现这一点 我使用以下PHP/MySQL通过数组创建: $result = mysql_query("SELECT * FROM happiness"); $array = array(); while($row = mysql_fetch_array($result)) { $array[] = $row[3]; $array[] = $row[2]; } echo js

我很难在Flot图上显示数据数组。我正在使用jQueryAjax/PHP/MySQL来实现这一点

我使用以下PHP/MySQL通过数组创建:

  $result = mysql_query("SELECT * FROM happiness");
  $array = array();
  while($row = mysql_fetch_array($result)) {
    $array[] = $row[3];
    $array[] = $row[2];
  }

  echo json_encode($array);
然后通过jQuery Ajax将其传递给Flot,如下所示:

$.ajax({                                      
      url: 'receive-happiness.php',   
      dataType: 'json',                      
      success: function(data)          
      {
            var graph_data = [data];              
            alert(graph_data);
            $.plot($("#graph"), [graph_data], options);
      }
    });
[ [23, 8], [23, 1], [24, 0], [25, 0], [26, 9], [27, 10], [28, 9] ]
当我发出警报
graph\u data
时,我得到以下信息:

23,8,23,1,24,0,25,0,26,9,27,10,28,9

但当我检查Flot图时,它只在
(23,8)
处显示一个数据点。出什么事了

您的图形数据应该是分组点坐标的数组

试试这个:

$result = mysql_query("SELECT * FROM happiness");
$array = array();
while($row = mysql_fetch_array($result)) {
  $array[] = array($row[3], $row[2]);
}

echo json_encode($array);
当您提醒图形数据时,它应该如下所示:

$.ajax({                                      
      url: 'receive-happiness.php',   
      dataType: 'json',                      
      success: function(data)          
      {
            var graph_data = [data];              
            alert(graph_data);
            $.plot($("#graph"), [graph_data], options);
      }
    });
[ [23, 8], [23, 1], [24, 0], [25, 0], [26, 9], [27, 10], [28, 9] ]
参见Flot文档