+ -
当前位置:首页 → 问答吧 → 利用ajax实现动态数据的问题

利用ajax实现动态数据的问题

时间:2011-07-27

来源:互联网

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <script src="./libraries/RGraph.common.core.js"></script>
  <script src="./libraries/RGraph.line.js"></script>
<div>
<div style="width: 800px">
  <div style="width: 450px; float: left">
<canvas id="cvs" width="600" height="250">[No canvas support]</canvas>
  </div>
  </div>
  </div>
<script>
  d1 = [];
// Pre-pad the arrays with 100 null values
  for (var i=0; i< 100; ++i) {
  d1.push(null);  
  }
  function getGraph(id, d1)
  {
  var graph = new RGraph.Line(id, d1);
  graph.Set('chart.background.barcolor1', 'black');
  graph.Set('chart.title.xaxis', 'Time');
  graph.Set('chart.filled', true);
  graph.Set('chart.fillstyle', ['#daf1fa', '#faa']);
  graph.Set('chart.colors', ['rgb(169, 222, 244)', 'red']);
  graph.Set('chart.linewidth', 3);
  graph.Set('chart.ymax', 20);
  graph.Set('chart.xticks', 25);
  return graph;
  }  
  function drawGraph (e)
  {
  // Clear the canvas and redraw the chart
  RGraph.Clear(document.getElementById("cvs"));
  var graph = getGraph('cvs', d1);
  graph.Draw();
  // Add some data to the data arrays
  d1.push(AjaxCall('http://1.58.109.173:33999/1,128,V',myCallback)); //这个http是我想获取数据的地址
// Get rid of the first values of the arrays
  if (d1.length > 100){
  d1 = RGraph.array_shift(d1);  
  }
  setTimeout(drawGraph,25);
  }  
  drawGraph();
</script>
</html>

作者: yuexuanyu   发布时间: 2011-07-27

我想通过这个代码实现读取后台数据并更新折线图,不考虑后台,只需要连接前台和获取数据网页即可,我在这里用了ajax,用d1.push()输出我获取的值,可是没有获得值,请问ajaxcall方法是封装在html5中了吧?我该引入那个.js文件,还有d1.push()里的格式该如何写

作者: yuexuanyu   发布时间: 2011-07-27