javascript - Firebase 数组转换为 AngularChart

标签 javascript angularjs ionic-framework firebase-realtime-database angular-chart

我试图打开这个数据库

enter image description here

使用 Angular 图作为雷达图。

我想知道如何将我的 Firebase 数组转变为与此 Angular 图表数组格式兼容的新数组?

  $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

我尝试过,但失败了

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

编辑: 这是我自己根据数字知识得出的答案

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

最佳答案

你实际上可以这样做

// 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);

关于javascript - Firebase 数组转换为 AngularChart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41156447/

相关文章:

javascript - 看不懂这个 Javascript 函数(函数重载)

javascript - Angular View ,如果未经身份验证,则显示单个 View

javascript - Angular slider 不显示

javascript - 大括号在 AngularJS 中无法一致工作

ionic-framework - @IonicPage 装饰器是否已弃用?

Angular 订阅 API 返回的数据

javascript - CSS显示: changes from none to block after it was changed from block to none时布局发生变化

javascript - 在 Fullcalendar 中,最长的事件总是垂直排列在最前面吗?

javascript - 如何在globe d3.js上显示国家名称

html - 为什么 ionic 标签没有正确呈现?