代码之家  ›  专栏  ›  技术社区  ›  mbilyanov

如何使用javascript获得一个移动的绘图?

  •  1
  • mbilyanov  · 技术社区  · 6 年前

    我试图创造一个流畅的情节。但是,我不确定要使用哪个绘图参数才能在底部的示例图像中获得结果。

    我的阴谋在这里: RandomSignalFlow

    HTML:

    <head>
      <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
    </head>
    <body>
      <div id="graph"></div>
    </body>
    

    JS:

    function rand() { 
      return Math.random();
    }
    
    Plotly.plot('graph', [{
      y: [1,2,3].map(rand),
      mode: 'lines',
      line: {color: '#80CAF6'}
    }]);
    
    var cnt = 0;
    
    var interval = setInterval(function() {
    
      Plotly.extendTraces('graph', {
        y: [[rand()]]
      }, [0])
    
      if(cnt === 100) clearInterval(interval);
    }, 300);
    

    因此,这将创建数据流,但随着数据的流入,绘图将不断地水平压缩。我在追求 tracking 行为(如下图所示)。

    我试着用 .shift() 裁剪数据的 X Y 但由于某些原因,这些组件不起作用。

    Example Flowing Plot

    与图像关联的项目是 here .

    0 回复  |  直到 6 年前