I'm developing an AngularJS application, working with Parse.com as the backend.
What I'm trying to achieve:
I have multiple answer scores (values) stored within an Array, I want to be able to add up each value within each Array and display the total of each set.
e.g
Set 1 [1,2,3] = 6 Points
Set 2 [1,1,1,1] = 4 Points
Current Problems:
No matter what example I attempt to use I can't seem to get this working.
Any help / advice would be helpful!
Controller JS:
var dashApp = angular.module('dashApp.controllers', ['chart.js']);
dashApp.controller("dashboardCtrl", function($scope, $http, $filter) {
$scope.parseRecommend = [];
// Question Answer Array
$scope.parseQ1P1 = [];
$scope.parseQ1P2 = [];
$scope.parseQ2P1 = [];
$scope.parseQ2P2 = [];
$scope.parseQ3P1 = [];
$scope.parseQ4P1 = [];
$scope.parseQ5P1 = [];
var hashmap = {};
$http({
method: 'GET',
url: 'https://api.parse.com/1/classes/Customers',
headers: {
'X-Parse-Application-Id': 'xxx',
'X-Parse-REST-API-Key': 'xxx'
}
})
.success(function(data, error) {
$scope.parseResults = data.results;
// Widget Data
angular.forEach($scope.parseResults, function(results) {
$scope.parseRecommend.push(results.question_4_p1);
// Get Question Anwsers
$scope.parseQ1P1.push(results.question_1_p1);
$scope.parseQ1P2.push(results.question_1_p2);
$scope.parseQ2P1.push(results.question_2_p1);
$scope.parseQ2P2.push(results.question_2_p2);
$scope.parseQ3P1.push(results.question_3_p1);
$scope.parseQ4P1.push(results.question_4_p1);
$scope.parseQ5P1.push(results.question_5_p1);
});
$scope.parseRecommend.forEach(function(elm) {
hashmap.hasOwnProperty(elm) ? ++hashmap[elm] : hashmap[elm] = 1
});
// Widget One
var yesAmount = hashmap.yes;
var noAmount = hashmap.no;
$scope.widgetone_data = [yesAmount, noAmount];
$scope.widgetone_label = ["Yes", "No"];
// Widget Two
$scope.widgettwo_label = ['Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'Q10'];
$scope.widgettwo_data = [
[65, 59, 100, 81, 56, 55, 40, 44, 87, 12],
[22, 33, 44, 11, 55, 6, 97, 5, 72, 45]
];
})
.error(function(data, error) {
alert('Failed, error code: ' + error.message);
});
});