【问题标题】:I have a setInterval function that graphs.我有一个绘制图表的 setInterval 函数。
【发布时间】:2016-12-02 09:13:01
【问题描述】:

但是我想停止 setInterval 函数而不让图形消失?当 setInterval 停止时,图形消失或至少绘制的最后 7 个点。我该怎么办?提前谢谢!

`

var graphingID = setInterval(function(){
  if (itertn == char.length){
    clearInterval(graphingID);
   }
  itertn++;
   //Add two random numbers for each dataset
  myLiveChart.addData([char[itertn], char[itertn]], ++latestLabel);
  // Remove the first point so we dont just add values forever 
  //updateDaw();
  myLiveChart.removeData(2);
}, 50);

`

【问题讨论】:

    标签: javascript angularjs d3.js graph chart.js


    【解决方案1】:

    可能是这样的吗?

    var graphingID = setInterval(function(){
      if (itertn == char.length){// is it time to stop? if yes clear interval
         clearInterval(graphingID);
       }
      else{// if not, go on as usual
    
          itertn++;
           //Add two random numbers for each dataset
          myLiveChart.addData([char[itertn], char[itertn]], ++latestLabel);
          // Remove the first point so we dont just add values forever 
          //updateDaw();
          myLiveChart.removeData(2);
     }
    }, 50);
    

    【讨论】:

      【解决方案2】:

      清除时不要继续:

      if (itertn == char.length){ clearInterval(graphingID); return; }
      

      【讨论】:

        猜你喜欢
        • 2019-03-15
        • 2016-11-02
        • 1970-01-01
        • 2021-09-19
        • 2016-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-20
        相关资源
        最近更新 更多