下面是我在高位图表上的简单图表。一切看起来都很好,但我现在唯一的问题是我的数据只有两个 2012-05-26 01:00:00、200 和 2012-05-26 02:00:00,300。y 轴看起来很好。但在 x 轴上,时间显示为从 17:00 开始,到 18:00 结束,甚至没有显示日期。可能是什么问题呢?
<?php
define('DB_HOST', '*******');
define('DB_USER', 'user1');
define('DB_PASSWORD', 'test1');
define('DB_DATABASE', 'db1');
$dbcnx = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db('db1');
$sql = "select unix_timestamp(datetime1) as datetime1, value1 from data";
$result = mysql_query($sql,$dbcnx);
$data = array();
while ($row = mysql_fetch_array($result)) {
//extract $row;
//$datetime1 = $row['dateTime1']*1000;
$datetime = $row['datetime1']*1000;
//echo $datetime;
echo $row['value1'];
$val = $row['value1'];
// convert from Unix timestamp to JavaScript time
$data[] = "[$datetime, $val]";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$(document).ready(function() {
//alert("TS");
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
series:
[{
data: [<?php echo join($data, ',') ?>]
}],
xAxis: { type: 'datetime'}
});
});
});
</script>
</head>
<body>
<script src="js/highcharts.js"></script>
<script src="js/modules/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>