侠们,我在做一个数据采集系统,传感器的数据一直往数据库写,在我的前台界面要实时显示,并且还能查询历史数据,补充:传感器虽然一直工作,但是我并不是要所有的数据,后台在采集的时候是按照设定好的时间,每天固定时刻或者一小时仅采集一次,然后存在数据库,数据库我在定义的时候,除了定义编号,数值,是不是还要定义时间,是不是采集的每条数据要存在数据库,这样会不会导致数据库不优化等等,还有别的方法吗?MySQL数据库性能优化时间戳
调试欢乐多
<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">
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Revenue vs. Overhead',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Amount'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: []
}
$.getJSON("data.json", function(json) {
options.xAxis.categories = json[0]['data'];
options.series[0] = json[1];
options.series[1] = json[2];
chart = new Highcharts.Chart(options);
});
});
</script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>
但是现在问题又有了,后台怎么去mysql的数据呢?去了以后又怎么转成json呢???
//每隔3秒自动调用方法,实现图表的实时更新
window.setInterval(getForm,3000);
});
$rows = array();
$rows['name'] = 'Revenue';
while($r = mysql_fetch_array($sth)) {
$rows['data'][] = $r['revenue'];
}好了 来一个完整地<?php
$con = mysql_connect("localhost","root","");if (!$con) {
die('Could not connect: ' . mysql_error());
}mysql_select_db("highcharts", $con);$sth = mysql_query("SELECT revenue FROM projections_sample");
$rows = array();
$rows['name'] = 'Revenue';
while($r = mysql_fetch_array($sth)) {
$rows['data'][] = $r['revenue'];
}$sth = mysql_query("SELECT overhead FROM projections_sample");
$rows1 = array();
$rows1['name'] = 'Overhead';
while($rr = mysql_fetch_assoc($sth)) {
$rows1['data'][] = $rr['overhead'];
}$result = array();
array_push($result,$rows);
array_push($result,$rows1);print json_encode($result, JSON_NUMERIC_CHECK);mysql_close($con);
?>