+ -
当前位置:首页 → 问答吧 → 关于AJAX只刷新数据 无页面刷新的问题

关于AJAX只刷新数据 无页面刷新的问题

时间:2011-07-25

来源:互联网

HTML code
<!DOCTYPE html>
<html>
<head>
    <script src="./libraries/RGraph.common.core.js"></script>
    <script src="./libraries/RGraph.common.annotate.js" ></script>
    <script src="./libraries/RGraph.common.context.js" ></script>
    <script src="./libraries/RGraph.common.tooltips.js" ></script>
    <script src="./libraries/RGraph.common.resizing.js" ></script>
    <script src="./libraries/RGraph.bar.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 = [];
    d2 = [];    
    // Pre-pad the arrays with 100 null values
    for (var i=0; i< 100; ++i) {
        d1.push(null);
        d2.push(null);
    }

    function getGraph(id, d1, d2)
    {
        var graph = new RGraph.Line(id, d1, d2);
        graph.Set('chart.background.barcolor1', 'black');
        graph.Set('chart.background.barcolor2', '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, d2);
        graph.Draw();
                // Add some data to the data arrays
        d1.push(RGraph.random(5, 10));
        d2.push(RGraph.random(5, 10));
                // Get rid of the first values of the arrays
        if (d1.length > 100) {
            d1 = RGraph.array_shift(d1);
            d2 = RGraph.array_shift(d2);
        }
        setTimeout(drawGraph,25);
    }    
    drawGraph();

</script>
</head>
</html>

麻烦看一下这段代码 我也感觉不到哪里有问题 求大神讲解

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

没用过RGraph,帮顶

作者: lsw645645645   发布时间: 2011-07-25

。。。这个问题我解决了,但是我想继续问一下用canvas标签绘制棒图的时候 怎么让棒图的数据值为变量,我一旦设置变量,页面就显示不出数据

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

继续附上代码一段
<!DOCTYPE html>
<html>
<head>
<body>
  <script src="./libraries/RGraph.common.core.js"></script>
  <script src="./libraries/RGraph.common.annotate.js" ></script>
  <script src="./libraries/RGraph.common.context.js" ></script>
  <script src="./libraries/RGraph.common.tooltips.js" ></script>
  <script src="./libraries/RGraph.common.resizing.js" ></script>
  <script src="./libraries/RGraph.bar.js" ></script>
<script scr="./libraries/RGraph.line.js"></script>
 <script>
  d1 = [];
  d2 = []; 
// Pre-pad the arrays with 100 null values
  for (var i=0; i< 100; ++i) {
  d1.push(null);
  d2.push(null);
  }
  window.onload=function (e)
  {  
var bar = new RGraph.Bar('cvs',['d1','d2']);
  bar.Set('chart.colors', ['blue', 'pink']);
  bar.Set('chart.labels.above', true);
  bar.Set('chart.shadow', true);
  bar.Set('chart.shadow.color', '#aaa');
  bar.Set('chart.strokestyle', 'rgba(0,0,0,0)');
  bar.Set('chart.adjustable', true);
  bar.Set('chart.labels', ['2000','2001']);
bar.Draw();
}
function drawGraph (e)
  {
  // Clear the canvas and redraw the chart
  RGraph.Clear(document.getElementById("cvs"));
  var bar = getGraph('cvs', d1, d2);
  bar.Draw();
  // Add some data to the data arrays
  d1.push(RGraph.random(5, 10));
  d2.push(RGraph.random(5, 10));
  // Get rid of the first values of the arrays
  if (d1.length > 100) {
  d1 = RGraph.array_shift(d1);
  d2 = RGraph.array_shift(d2);
  }
  setTimeout(drawGraph,25);
  }  
  drawGraph();

</script>
  <div>
   
  <div style="width: 800px">
  <div style="width: 450px; float: left">
  <canvas id="cvs" width="500" height="200">[No canvas support]</canvas>
   
  </div>
  </div>
  </div>
</body>
</head>
</html>

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

还没做过html5呢

作者: xuexiaodong2009   发布时间: 2011-07-25