$ scope.graphPlots2包含要绘制的所有痕迹。
for(c=0; c < $scope.graphPlots2.length; c++ ){
if(c == 0){
Plotly.newPlot(graphRender, [$scope.graphPlots2[c]], $scope.layout2);
}else{
Plotly.addTraces(graphRender, $scope.graphPlots2[c]);
}
}
它不会抛出错误,但视图(图形)不会更新(显示新添加的跟踪),直到循环结束。我希望看到每条迹线都显示为已添加。
循环结束后的graphRender.data:
[
{
"name": "DOC.1050 - Weight - ",
"x": [
"2011-01-01 00:01:00",
"2011-02-01 00:01:00",
"2011-03-01 00:01:00",
"2011-04-01 00:01:00",
"2011-05-01 00:01:00",
"2011-05-27 00:01:00"
],
"y": [
103,
102,
221.7,
102.7,
99.8,
108
],
"type": "scatter",
"visible": true,
"line": {
"shape": "linear"
},
"mode": "lines",
"uid": "db720d"
},
{
"name": "DOC.1050 - blood pressure - ",
"x": [
"2011-01-01 00:01:00",
"2011-02-01 00:01:00",
"2011-03-04 00:01:00",
"2011-04-01 00:01:00",
"2011-05-01 00:01:00",
"2011-05-25 00:01:00"
],
"y": [
9000,
19980,
8800,
8700,
8000,
7500
],
"type": "scatter",
"visible": true,
"line": {
"shape": "linear"
},
"mode": "lines",
"uid": "4631f2"
},
{
"name": "DOC.4258 - Weight - ",
"x": [
"2011-01-02 00:01:00",
"2011-02-02 00:01:00",
"2011-03-02 00:01:00",
"2011-04-02 00:01:00",
"2011-05-02 00:01:00"
],
"y": [
299.8,
202.7,
201,
204,
201.7
],
"type": "scatter",
"visible": true,
"line": {
"shape": "linear"
},
"mode": "lines",
"uid": "23afcd"
},
{
"name": "DOC.47007 - Weight - ",
"x": [
"2011-01-03 00:01:00",
"2011-03-03 00:01:00",
"2011-03-20 00:01:00",
"2011-04-05 00:01:00",
"2011-05-01 00:01:00",
"2011-05-27 00:01:00"
],
"y": [
92,
68,
92.7,
79.8,
181.7,
41
],
"type": "scatter",
"visible": true,
"line": {
"shape": "linear"
},
"mode": "lines",
"uid": "64f6fb"
}
]
答案 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);
}
});