Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm trying to create a chart. And here is my html code

<div class="card">
   <div class="item item-divider">
     Approved and Pending Members 
   </div>
   <div class="item item-text-wrap">
      <canvas id="line" class="chart chart-bar" data="memStatData" labels="status" legend="true" series="stats" options="{showTooltips: true}">       </canvas>
   </div>
</div>

and my JS:

 $scope.status = ["Approved", "Pending"];
  $scope.stats = ["Stats"];
  $scope.memStatData = [];

  var query = "SELECT sum(members.status='P') as pending, "
  + "sum(members.status='A') as approved FROM members";
  $cordovaSQLite.execute(db, query, [])
  .then(function(res){
      $scope.memStatData = res.rows.item(0);
      console.log(JSON.stringify($scope.memStatData));
  }, function(err){
      $cordovaToast.showShortBottom('Something Went Wrong').then(function(success){}, function(err){});
      console.log(err.message);
  });

How can i display the sum of pending and approved in my chart? Thanks.

share|improve this question
    
It looks like you are trying to create a bar chart? Take a look at the example usage (chartjs.org/docs/#bar-chart-example-usage), especially the part about datasets and you will see how to feed your data to the chart. Ask a more specific question if you get stuck on that. – jeff carey Feb 3 at 15:41

I figured it out already. Let me know if I did it right. But the chart gets values from my database.

  $scope.status = ["Approved", "Pending"];
          $scope.stats = ["Stats"];

var query = "SELECT sum(members.status='P') as pending, "
      + "sum(members.status='A') as approved FROM members";
      $cordovaSQLite.execute(db, query, [])
      .then(function(res){
            $scope.memStatData= res.rows.item(0);
            var p = $scope.memStatData.pending;
            var a = $scope.memStatData.approved;
            console.log(p);
            console.log(a);
            $scope.memStatData = [
                [p, a]
            ];
      }, function(err){
          // $cordovaToast.showShortBottom('Something Went Wrong').then(function(success){}, function(err){});
          console.log(err.message);
      });
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.