Angularjs Element duplicating

Asked

Viewed 81 times

1

I made a chart with Morris.js https://morrisjs.github.io/morris.js/donuts.html

and put it inside a return of a query, so far everything right, but when I call this query again to generate other data on the graph, it generates another graph, is duplicating, instead of just exchanging information, it creates another graph and is 2

Erro angularjs

As I change the option, it generates a new chart...

My code

 $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}
          ]
        });
      });
};

1 answer

1


I do not know this morrisjs, but giving a search I found something that may help.

Try to create a single chart 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}
      ]);
  });
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.