Firebase Array into AngularChart

116 views Asked by At

I tried to turn this database

enter image description here

to be radar chart using angular-chart.

I'm wondering how to turn my Firebase array to be a new array compatible with this angular-chart array format?

  $scope.labels =["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running", "Running", "Running", "Running"];
            $scope.data = [[12,14,23,56,64,34,46,34,76,12]];

enter image description here

I tried this but it failed

 $scope.labels =$scope.results.$id;
 $scope.data = [$scope.results.$value];

Edited: this is my own answer base on digit's knowledge

  $scope.labels = [], $scope.dataRaw = [], $scope.data = [];

              fireBaseData.refUser().child($scope.user_info.uid).child("result")
                .orderByValue()

                .on("value", function(snapshot){
                   snapshot.forEach(function(data){
                     console.log("The "+ data.key()+" score is "+ data.val());
                     $scope.labels.push(data.key());
                     $scope.dataRaw.push(data.val());
                    });
                });
                $scope.data.push($scope.dataRaw);
1

There are 1 answers

6
digit On BEST ANSWER

You can actually by doing this

// Initialise array
$scope.labels = [], $scope.dataRaw = [], $scope.data = [];

// Fetch results in form of array of object 
angular.forEach($scope.results, function (obj) {
    $scope.labels.push(obj["$id"]);
    $scope.dataRaw.push(obj["$value"]);
});

// Store data array into new array
$scope.data.push($scope.dataRaw);