 |
|
โปรแกรมไว้สำหรับ สร้างกราฟ realtime โดยใช้ java script
ตอนนี้ติดปัญหาตรง
อ่านค่าจาก php เพื่อนำค่ายัดลง list ในจาวาสคริป
คือ มันอ่านค่าซ้ำตลอด ถ้ากดf5 ถึงจะได้ค่าใหม่
จากcodeผมให้วนขึ้นมาในfunction getData ทุกครั้งเพื่อทำการอ่านค่าใหม่เพื่อยัดลง [ ]
แต่สิ่งที่เกิดปัญหาคือ มันอ่านค่าเดียวตลอด ทั้งๆที่จาก code วนมาอ่านค่าจากphp ใหม่ทุกครั้ง
อยากขอคำชี้แนะท่านผู้รู้ทุกๆท่านที่แวะเข้ามาครับ ผมจะแก้ปัญหานี้อย่างไรดี
Code (JavaScript)
<script type="text/javascript" >
$(function () {
// we use an inline data source in the example, usually data would
// be fetched from a server
var data = [], totalPoints = 5;
function getData() {
if (data.length > 0)
data = data.slice(1);
document.write(data+ "<br>");
while (data.length <= totalPoints) {
<?php
$oid=268435456+5;
$host = "10.255.206.11";
$snrDown1 = snmpget($host, "private", ".1.3.6.1.2.1.10.94.1.1.3.1.1.$oid");
$index1 = snmpget($host, "public", ".1.3.6.1.2.1.10.94.1.1.3.1.4.$oid");
$snr1 = snmpget($host, "public", ".1.3.6.1.2.1.10.94.1.1.3.1.4.$oid");
$snr1_1=ereg_replace("[^[:digit:]]","", $snr1 ) ;
echo 'data.push(' . $snr1_1 . ')' . "\n"; ?>
}
document.write(data+ "<br> ");
// zip the generated y values with the x values
var res = [];
for (var i = 0; i < data.length; ++i)
document.write(length+ "<br />");
res.push([i, data[i]])
document.write(i+ "<br />");
//document.write(data[i]+ "<br />");
document.write(res+ "<br /><br />");
return res;
}
// setup control widget
var updateInterval = 3000;
$("#updateInterval").val(updateInterval).change(function () {
var v = $(this).val();
if (v && !isNaN(+v)) {
updateInterval = +v;
if (updateInterval < 1)
updateInterval = 1;
if (updateInterval > 200000)
updateInterval = 200000;
$(this).val("" + updateInterval);
}
});
// setup plot
var options = {
series: { shadowSize: 0 }, // drawing is faster without shadows
yaxis: { show : true },
xaxis: { show: false }
};
var plot = $.plot($("#placeholder"), [ getData() ], options);
function update() {
plot.setData([ getData() ]);
// since the axes don't change, we don't need to call plot.setupGrid()
plot.draw();
setTimeout(update, updateInterval);
//window.location.href = 'readdbonly.php';
}
update();
});
</script>
Tag : PHP, MySQL, JavaScript, jQuery
|
|
 |
 |
 |
 |
Date :
2011-09-03 19:39:02 |
By :
goki001 |
View :
1175 |
Reply :
0 |
|
 |
 |
 |
 |
|
|
|
 |