0
我正在使用php从mySql数据库中提取数据以使用flot绘制图表。查询工作正常,但运行代码时没有显示图形。图中应该出现一个空白区域。以下是我有: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>
谢谢你让我知道!但是,我添加它,它仍然不起作用: var dataset1 = <?php echo json_encode($ dataset1);?>; $ .plot($(“#placeholder”),[dataset1],{xaxis:{mode:“categories”}}); – user99592
@ user99592,给出“理智”的数据,它适用于我:http://jsfiddle.net/Gz8yW/1/ – Mark