Angularjs Duplicating element

1

I made a chart with Morris.js link

I put it inside a query return, so that's fine, but when I call that query again to generate other data in the graph, it generates another graph, it's duplicating, instead of just exchanging information, it creates another graphic and gets 2

AsIchangetheoption,itwillgenerateanewgraphic...

Mycode

$scope.selectAction=function(myOption){$http.get('http://localhost/Angularjs/php/TotalAlunos.php?cod='+$scope.myOption.id).then(function(result){Morris.Donut({element:'donut-example',data:[{label:"In-Store Sales", value: result.data.total},
            {label: "Mail-Order Sales", value: 20}
          ]
        });
      });
};
    
asked by anonymous 27.04.2016 / 14:33

1 answer

1

I do not know this morrisjs, but giving a researched I found something that might help.

Try to create a chart only and just update your data on each call. Something like this:

var donut = Morris.Donut({
      element: 'donut-example',
      data: [
          {label: "In-Store Sales", value: 0},
          {label: "Mail-Order Sales", value: 0}
      ]
    });

 $scope.selectAction = function(myOption) {
   $http.get('http://localhost/Angularjs/php/TotalAlunos.php?cod=' + $scope.myOption.id).then(function(result){    
    donut.setData([
        {label: "In-Store Sales", value: result.data.total},
        {label: "Mail-Order Sales", value: 20}
      ]);
  });
};
    
27.04.2016 / 17:38