Firebase 数组到 AngularChart
Firebase Array into AngularChart
我试图打开这个数据库
使用 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]];
我试过了但是失败了
$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);
我试图打开这个数据库
使用 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]];
我试过了但是失败了
$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);