[Chartjs]-Doughnut chart updates with twice the data

1๐Ÿ‘

try to change in the mainInterval function

doughnutData = '';

with

$scope.doughnutData = [];

In angular you get access to the fields by the $scope object

1๐Ÿ‘

 mainInterval = $interval(function() {
         $scope.doughnutData = [];
        $http.get('https://api.myjson.com/bins/59zvx').success(function(returnedData) {
          $scope.username = returnedData.name;
          $scope.totalscore = returnedData.totalScore.toFixed(3);

          returnedData.models.forEach(function(x) {
            var score = x.score.toFixed(3);
            console.debug(score);
            if (score >= 75) {
              $scope.doughnutData.push({
                'value': x.score,
                'color': '#F7464A',
                'highlight': '#FF5A5E',
                'label': x.name
              });
            } else if (score >= 50) {
              $scope.doughnutData.push({
                'value': x.score,
                'color': '#FDB45C',
                'highlight': '#FFC870',
                'label': x.name
              });
            } else {
              $scope.doughnutData.push({
                'value': x.score,
                'color': '#424242',
                'highlight': '#686868',
                'label': x.name
              });
            }
          });
          $scope.doughnutData = sortByKey($scope.doughnutData, 'value');
          myDoughnut.segments = $scope.doughnutData;
          myDoughnut.update();
        });
      }, 5000);

Leave a comment