0

我正在使用 php 从 mySql 数据库中提取数据以使用 flot 绘制图形。查询工作正常,但运行代码时没有显示图表。图表应该在的地方出现了一个空白区域。这是我所拥有的:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Flot Graph</title>
<link href="layout.css" rel="stylesheet" type="text/css">

<script language="javascript" type="text/javascript" src="../jquery.js"></script>
<script language="javascript" type="text/javascript" src="../jquery.flot.js"></script>

 </head>
<body>
<h1>Flot Graph</h1>

<div  id="placeholder" style="width:600px;height:300px;"></div>

<?php

$mysqli=new mysqli('localhost','root',"",'simpledb');

  $sql="select name, age from `people` where age=23";


  $results = $mysqli->query($sql);
  if ($results)
  {
    while ($row=$results->fetch_assoc())
    {
      $dataset1[] = array($row['name'],$row['age']);
    }
  }
  else
  {

    echo "Error";
  }

?>


<script type="text/javascript">
var dataset1 = <?php echo json_encode($dataset1); ?>;
$(function () 
{
$.plot($("#placeholder"), [
 {
     data: dataset1,
     bars: {show: true}
    }
]);
});
</script>



 </body>
</html>
4

2 回答 2

1

看起来您的 x 值是字符串,但您还没有包含类别插件

于 2013-10-31T12:32:04.857 回答
0

感谢大家。我让它工作。我不确定问题是什么,但在我将 javascript 部分更改为:

$(function () 
{

$.plot("#placeholder", [ dataset1 ], {
  series: {
    bars: {
      show:true,
      barWidth: 0.6,
      align: "center"
      }
    },
    xaxis: {
      mode: "categories",
      tickLength:0
      }
    });

});

于 2013-11-01T10:56:22.180 回答