I'm working on a statistics view via Angular-Chart for a shoppinglist-App. It should show a graph of all spended costs by every user for a year. Now this is how I generate the JSON for the Chart:
$scope.data = {
        series: users,
        data: []
    };
    console.log(chartdata);
    $scope.load = function(){
        for(var i = 0; i< months.length; i++){
            for(var z = 0; z < chartdata.length; z++){
                var obj = chartdata[z];
                if(obj.year == $scope.dt.getFullYear()){
                    if(obj.month == months[i]){
                        for(var t =0; t < users.length;t++){
                            if(obj.name == users[t]){
                                usercosts[t] = (usercosts[t] + obj.price);
                                console.log(obj.price);
                                console.log(usercosts);
                            }
                        }
                    }
                }
            }
            console.log(usercosts);
            $scope.data.data.push({x:months[i],y: usercosts});
            for(var p = 0; p < users.length; p++){
                usercosts[p]=0;
            }
        }
        console.log($scope.data.data);
    };
The output in the console looks like this:
[0, 0]
44
[44, 0]
[44, 0]
[0, 0]
[0, 0]
7
[7, 0]
[7, 0]
20
[20, 0]
[20, 0]
5
[5, 0]
[5, 0]
[0, 0]
[0, 0]
[0, 0]
[0, 0]
[0, 0]
The array is filled fine but the push statement :
$scope.data.data.push({x:months[i],y: usercosts});
just dont work right. "usercosts" is in every line the same value.... the last one; in this case 0. Although I push before I go through the next month. I dont now what to do anymore and would appreciate to get some smart answers from you. best wishes Christoph