2016-07-07 47 views
1
for(c=0; c < $scope.graphPlotsChunk.length; c++){ 
     if(c == 0){ 
      Plotly.newPlot(graphRender, [$scope.graphPlots2[c]], $scope.layout2); 
     }else{ 
      setTimeout(function() { 
       $scope.testCounter.push(_.clone(c)); 
       console.log($scope.testCounter); 
       Plotly.addTraces(graphRender, $scope.graphPlots2[c]); 
      },0); 
     } 
    } 

调用Plotly addTraces抛出一个错误,因为unsyncroniced反“C”: enter image description heresetTimeout在代码角度破解位置?

没有超时的错误,但不会痕迹反映视图,直至循环结束。我希望看到的痕迹一个接一个地显示大数据绘图,可能会很慢,所以至少在代码运行时会发生一些变化

任何建议,不知道该从哪里下去!

+0

http://community.plot.ly/t/update-view-after-every-iteration-plotly-js- addtraces-loop/1479/5 –

+0

你尝试过'$ timeout()'吗? – theaccordance

+0

不在这里,我会给它去 –

回答

0

使用foreach而不是为循环某种程度上解决了这个问题,,,

$scope.graphPlots2.forEach(function(trace, i) { 
    if (i == 0) { 
     Plotly.newPlot('graphRender', [trace], $scope.layout2); 
    } else { 
     setTimeout(function() { 
      Plotly.addTraces('graphRender', trace); 
     }, 0); 
    } 
}); 
+0

这不仅仅是对'forEach'的改变;这是完全不同的代码。看起来很明显,你遗漏了你原来的问题。 –

+0

@MikeMcCaughan是的你是对的,我编辑原始帖子,以反映原始错误/代码 –