我在制作Flot图形时遇到问题。 这是图形的代码 我还包括PHP的print_r输出。 所以基本上我最大的问题是使用json编码或图形显示本身我只是找不到错误...
<!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>Graph of Energy Consumption</title>
<link href="layout.css" rel="stylesheet" type="text/css"></link>
<!--[if IE]><script language="javascript" type="text/javascript" src="flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="flot/jquery.js"></script>
<script language="javascript" type="text/javascript" src="flot/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="flot/jquery.flot.selection.js"></script>
</head>
<body>
<h1>Energy</h1>
<p>Zoom to:
<button id="nineties">half hour</button>
<button id="ninetynine">1 hour</button>
<button id="12hour">12 hours</button>
<button id="24hour">24 hours</button>
<button id="48hour">48 hours</button>
<button id="Refresh">Refresh</button></p>
<?php
include 'connect.php';
$link=Connection();
$result=mysql_query("SELECT * FROM `tempLog` ORDER BY `timeStamp` DESC",$link);
$data = array();
$max = 0;
while($row = mysql_fetch_array($result))
{
$data[] = array( $row['timeStamp'], $row['temperature'] );
}
print_r($data);
?>
<div id="placeholder" style="width:800px;height:400px;"></div>
<p></p>
<div id="overview" style="margin-left:20px;margin-top:20px;width:780px;height:100px"></div>
<script id="source" language="javascript" type="text/javascript">
var data = <?php echo json_encode($data); ?>;
$(function () {
var options = {
xaxis: { mode: "time" },
selection: { mode: "xy" },
};
var plot = $.plot($("#placeholder"), [ data ], options);
var overview = $.plot($("#overview"), [ data ], {
series: {
lines: { show: true, lineWidth: 1 },
shadowSize: 0
},
xaxis: { ticks: [], mode: "time" },
yaxis: { ticks: [], min: 0, max: 5000 },
selection: { mode: "xy" }
});
$("#placeholder").bind("plotselected", function (event, ranges) {
// clamp the zooming to prevent eternal zoom
if (ranges.xaxis.to - ranges.xaxis.from < 0.00001)
ranges.xaxis.to = ranges.xaxis.from + 0.00001;
if (ranges.yaxis.to - ranges.yaxis.from < 0.00001)
ranges.yaxis.to = ranges.yaxis.from + 0.00001;
// do the zooming
plot = $.plot($("#placeholder"), [ data ],
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to }
}));
// don't fire event on the overview to prevent eternal loop
overview.setSelection(ranges, true);
});
$("#overview").bind("plotselected", function (event, ranges) {
plot.setSelection(ranges);
});
$("#nineties").click(function () {
$.plot($("#placeholder"), [data], {
xaxis: {
mode: "time",
min: (new Date()).getTime()-1800000,
max: (new Date()).getTime()
},
selection: { mode: "xy" }
});
});
$("#ninetynine").click(function () {
$.plot($("#placeholder"), [data], {
xaxis: {
mode: "time",
min: (new Date()).getTime()-3600000,
max: (new Date()).getTime()
},
selection: { mode: "xy" }
});
});
$("#12hour").click(function () {
$.plot($("#placeholder"), [data], {
xaxis: {
mode: "time",
min: (new Date()).getTime()-43200000,
max: (new Date()).getTime()
},
selection: { mode: "xy" }
});
});
$("#24hour").click(function () {
$.plot($("#placeholder"), [data], {
xaxis: {
mode: "time",
min: (new Date()).getTime()-86400000,
max: (new Date()).getTime()
},
selection: { mode: "xy" }
});
});
$("#48hour").click(function () {
$.plot($("#placeholder"), [data], {
xaxis: {
mode: "time",
min: (new Date()).getTime()-172800000,
max: (new Date()).getTime()
},
selection: { mode: "xy" }
});
});
$("#Refresh").click(function () {
});
});
</script>
</body>
</html>
Array ( [0] => Array ( [0] => 2015-04-16 22:47:27 [1] => 25 ) [1] => Array ( [0] => 2015-04-16 22:42:21 [1] => 25 ) [2] => Array ( [0] => 2015-04-16 22:37:15 [1] => 25 ) [3] => Array ( [0] => 2015-04-16 22:32:09 [1] => 24 ) [4] => Array ( [0] => 2015-04-16 22:27:03 [1] => 24 ) [5] => Array ( [0] => 2015-04-16 22:21:56 [1] => 23 ) [6] => Array ( [0] => 2015-04-16 22:16:50 [1] => 23 ) [7] => Array ( [0] => 2015-04-16 22:11:44 [1] => 24 ) [8] => Array ( [0] => 2015-04-16 22:06:38 [1] => 24 ) [9] => Array ( [0] => 2015-04-16 22:01:32 [1] => 24 ) [10] => Array ( [0] => 2015-04-16 21:56:25 [1] => 24 ) [11] => Array ( [0] => 2015-04-16 21:51:19 [1] => 24 ) [12] => Array ( [0] => 2015-04-16 21:46:13 [1] => 24 ) [13] => Array ( [0] => 2015-04-16 21:41:07 [1] => 24 ) [14] => Array ( [0] => 2015-04-16 21:36:01 [1] => 25 ) [15] => Array ( [0] => 2015-04-16 21:30:55 [1] => 25 ) [16] => Array ( [0] => 2015-04-16 21:30:07 [1] => 25 ) [17] => Array ( [0] => 2015-04-16 21:27:56 [1] => 25 ) [18] => Array ( [0] => 2015-04-16 21:27:40 [1] => 25 ) [19] => Array ( [0] => 2015-04-16 21:27:24 [1] => 25 ) [20] => Array ( [0] => 2015-04-16 21:27:18 [1] => 25 ) [21] => Array ( [0] => 2015-04-16 21:22:40 [1] => 25 ) [22] => Array ( [0] => 2015-04-16 21:22:04 [1] => 25 ) [23] => Array ( [0] => 2015-04-16 21:21:53 [1] => 25 ) [24] => Array ( [0] => 2015-04-16 21:21:42 [1] => 25 ) [25] => Array ( [0] => 2015-04-16 21:21:26 [1] => 26 ) [26] => Array ( [0] => 2015-04-16 21:21:10 [1] => 26 ) [27] => Array ( [0] => 2015-04-16 21:20:54 [1] => 25 ) [28] => Array ( [0] => 2015-04-16 21:20:38 [1] => 25 ) [29] => Array ( [0] => 2015-04-16 21:20:22 [1] => 25 ) [30] => Array ( [0] => 2015-04-16 21:20:07 [1] => 25 ) [31] => Array ( [0] => 2015-04-16 21:19:51 [1] => 25 ) [32] => Array ( [0] => 2015-04-16 21:19:35 [1] => 25 ) [33] => Array ( [0] => 2015-04-16 21:19:19 [1] => 26 ) [34] => Array ( [0] => 2015-04-16 21:19:03 [1] => 25 ) [35] => Array ( [0] => 2015-04-16 21:18:47 [1] => 25 ) [36] => Array ( [0] => 2015-04-16 21:18:31 [1] => 25 ) [37] => Array ( [0] => 2015-04-16 21:18:15 [1] => 25 ) [38] => Array ( [0] => 2015-04-16 21:17:59 [1] => 25 ) [39] => Array ( [0] => 2015-04-16 21:17:43 [1] => 25 ) [40] => Array ( [0] => 2015-04-16 21:17:27 [1] => 25 ) [41] => Array ( [0] => 2015-04-16 21:17:11 [1] => 25 ) [42] => Array ( [0] => 2015-04-16 21:16:55 [1] => 25 ) [43] => Array ( [0] => 2015-04-16 21:16:40 [1] => 25 ) [44] => Array ( [0] => 2015-04-16 21:16:24 [1] => 25 ) [45] => Array ( [0] => 2015-04-16 21:16:08 [1] => 25 ) [46] => Array ( [0] => 2015-04-16 21:15:52 [1] => 25 ) [47] => Array ( [0] => 2015-04-16 21:15:36 [1] => 25 ) [48] => Array ( [0] => 2015-04-16 21:15:20 [1] => 26 ) [49] => Array ( [0] => 2015-04-16 21:15:04 [1] => 26 ) [50] => Array ( [0] => 2015-04-16 21:14:48 [1] => 26 ) [51] => Array ( [0] => 2015-04-16 21:14:32 [1] => 26 ) [52] => Array ( [0] => 2015-04-16 21:14:16 [1] => 29 ) [53] => Array ( [0] => 2015-04-16 21:14:00 [1] => 29 ) [54] => Array ( [0] => 2015-04-16 21:13:44 [1] => 25 ) [55] => Array ( [0] => 2015-04-16 21:13:35 [1] => 25 ) [56] => Array ( [0] => 2015-04-16 21:13:17 [1] => 25 ) )