如何在dygraph链接交互中插入csv文件

时间:2015-07-14 04:11:06

标签: javascript dygraphs

  

我在dygraph中有链接交互的例子,但我不知道如何链接我的csv文件。我尝试用我的csv文件替换r。,   请指导我。,   我试着通过将r声明为te1.csv我得到空白图

IFS=

  

在此我完全删除了r并直接声明了csv文件o / p是它的读取csv但是日,月,年显示的是2011年1月的数据,而csv文件中没有这些数据

<!DOCTYPE html>
<html>
  <head>
    <title>noise</title>
     <script type="text/javascript"
  src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.0/dygraph-combined-dev.js"></script>
  <script type="text/javascript"
  src=" http://dygraphs.com/dygraph-dev.js"></script>

  </head>
  <body>
    <div id="div_g"></div>
    <div id="output"></div>
    <b>Zoom:</b>
      <a href="#" onclick="zoom(3600)">hour</a>
      <a href="#" onclick="zoom(86400)">day</a>
      <a href="#" onclick="zoom(604800)">week</a>
      <a href="#" onclick="zoom(30 * 86400)">month</a>
      <a href="#" onclick="reset()">full</a>
    <b>Pan:</b>
      <a href="#" onclick="pan(-1)">left</a>
      <a href="#" onclick="pan(+1)">right</a>

    <script type="text/javascript">
    var r = ["te1.csv" ];
      var base_time = Date.parse("date");
      var num = 24 * 0.25 * 365;
      for (var i = 0; i < num; i++) {
        r.push([ new Date(base_time + i * 3600 * 1000),
                 
               ]);
      }
      var orig_range = [ r[0][0].valueOf(), r[r.length - 1][0].valueOf() ];
    
     var date = new Date(),
            output = document.getElementById( 'output' ),
            dateString = date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear().toString().substr(2,2);
               
        output.innerHTML = dateString;
        
       
      g2 = new Dygraph(
            document.getElementById("div_g"),
            r, {
              rollPeriod: 7,
              animatedZooms: true,
              // errorBars: true,
              width: 1000,
              height: 500,
             xlabel: 'date',
                                ylabel: 'Pressure',
            }
          );
      var desired_range = null;
      function approach_range() {
        if (!desired_range) return;
        // go halfway there
        var range = g2.xAxisRange();
        if (Math.abs(desired_range[0] - range[0]) < 60 &&
            Math.abs(desired_range[1] - range[1]) < 60) {
          g2.updateOptions({dateWindow: desired_range});
          // (do not set another timeout.)
        } else {
          var new_range;
          new_range = [0.5 * (desired_range[0] + range[0]),
                       0.5 * (desired_range[1] + range[1])];
          g2.updateOptions({dateWindow: new_range});
          animate();
        }
      }
      function animate() {
        setTimeout(approach_range, 50);
      }
      function zoom(res) {
        var w = g2.xAxisRange();
        desired_range = [ w[0], w[0] + res * 1000 ];
        animate();
      }
      function reset() {
        desired_range = orig_range;
        animate();
      }
      function pan(dir) {
        var w = g2.xAxisRange();
        var scale = w[1] - w[0];
        var amount = scale * 0.25 * dir;
        desired_range = [ w[0] + amount, w[1] + amount ];
        animate();
      }
    </script>
  </body>
</html>
  

我从这个例子中得到了上面的代码

<!DOCTYPE html>
<html>
  <head>
    <title>noise</title>
     <script type="text/javascript"
  src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/1.1.0/dygraph-combined-dev.js"></script>
  <script type="text/javascript"
  src=" http://dygraphs.com/dygraph-dev.js"></script>

  </head>
  <body>
    <div id="div_g"></div>
    <div id="output"></div>
    <b>Zoom:</b>
      <a href="#" onclick="zoom(3600)">hour</a>
      <a href="#" onclick="zoom(86400)">day</a>
      <a href="#" onclick="zoom(604800)">week</a>
      <a href="#" onclick="zoom(30 * 86400)">month</a>
      <a href="#" onclick="reset()">full</a>
    <b>Pan:</b>
      <a href="#" onclick="pan(-1)">left</a>
      <a href="#" onclick="pan(+1)">right</a>

    <script type="text/javascript">


      g2 = new Dygraph(
            document.getElementById("div_g"),
          te1.csv, {
              rollPeriod: 7,
              animatedZooms: true,
              // errorBars: true,
              width: 1000,
              height: 500,
             xlabel: 'date',
                                ylabel: 'Pressure',
            }
          );
      var desired_range = null;
      function approach_range() {
        if (!desired_range) return;
        // go halfway there
        var range = g2.xAxisRange();
        if (Math.abs(desired_range[0] - range[0]) < 60 &&
            Math.abs(desired_range[1] - range[1]) < 60) {
          g2.updateOptions({dateWindow: desired_range});
          // (do not set another timeout.)
        } else {
          var new_range;
          new_range = [0.5 * (desired_range[0] + range[0]),
                       0.5 * (desired_range[1] + range[1])];
          g2.updateOptions({dateWindow: new_range});
          animate();
        }
      }
      function animate() {
        setTimeout(approach_range, 50);
      }
      function zoom(res) {
        var w = g2.xAxisRange();
        desired_range = [ w[0], w[0] + res * 1000 ];
        animate();
      }
      function reset() {
        desired_range = orig_range;
        animate();
      }
      function pan(dir) {
        var w = g2.xAxisRange();
        var scale = w[1] - w[0];
        var amount = scale * 0.25 * dir;
        desired_range = [ w[0] + amount, w[1] + amount ];
        animate();
      }
    </script>
  </body>
</html>

  

我用csv文件替换了r,但是月,小时,日,周的过滤器不起作用

0 个答案:

没有答案