javascript - Highcharts bar chart animation only working on 1 series -
i refreshing data bar chart every x seconds webservice , color coding bar based on value. angular $interval using looks this:
maininterval = $interval(function() { console.debug("interval"); (x = 0; x < 5; x++) { var temp = math.random() * 100; if (temp > 75) { $scope.chart.series[x].update({ color: "red" }); $scope.chart.series[x].setdata([temp]); } else if (temp > 50) { $scope.chart.series[x].update({ color: "orange" }); $scope.chart.series[x].setdata([temp]); } else if (temp > 25) { $scope.chart.series[x].update({ color: "yellow" }); $scope.chart.series[x].setdata([temp]); } else { $scope.chart.series[x].update({ color: "grey" }); $scope.chart.series[x].setdata([temp]); } } }, 5000); but issue having once goes through interval first time, animation no longer shows bottom 4 bars, top one. example if change interval to
maininterval = $interval(function() { console.debug("interval"); (x = 0; x < 5; x++) { var temp = math.random() * 100; $scope.chart.series[x].setdata([temp]); } }, 5000); the animations between cycles works colors don't change obviously. ideas address this? here plunker working on.
the problem series.update() remove nice animation. workaround first update colors, setdata(). example: http://plnkr.co/edit/nbzypwoldcrghq4itf59?p=preview - 2 separate for's , need call twice chart.redraw(). it's matter between performance vs design ;)
maininterval = $interval(function() { (x = 0; x < 5; x++) { var temp = math.random() * 100, color; if (temp > 75) { color = "red"; } else if (temp > 50) { color = "orange"; } else if (temp > 25) { color = "yellow"; } else { color = "grey"; } $scope.chart.series[x].update({ color: color, nextdata: [temp] },false); } $scope.chart.redraw(); $.each( $scope.chart.series, function(i, s) { s.setdata(s.options.nextdata, false); }); $scope.chart.redraw(); }, 5000);
Comments
Post a Comment