Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

i have this static data:

  $scope.data = {
                    labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
                    datasets: [
                        {
                            label: 'My First dataset',
                            fillColor: 'rgba(220,220,220,0.2)',
                            strokeColor: 'rgba(220,220,220,1)',
                            pointColor: 'rgba(220,220,220,1)',
                            pointStrokeColor: '#fff',
                            pointHighlightFill: '#fff',
                            pointHighlightStroke: 'rgba(220,220,220,1)',
                            data: [75, 59, 80, 81, 56, 55, 40, 84, 64, 120, 132, 87]
                        }

                    ]
                };

My problem is: my real data come from the backend heres returned JSON Object :

[{"number":2,"des":"Ceintures De Sécurités Passagères","la_date":1506960648000},{"number":7,"des":"Ceintures De Sécurité Conducteur","la_date":1509542654000},{"number":1,"des":"Ceintures De Sécurités Passagères","la_date":1512134781000}]

I used the for loop , to loop the data:

 getIncidentDepartByMonthFromTo.forEach(function(data) {
               // charCtrl.toto.push($filter('monthName')(monthNumber));
                var monthNumber=$filter('date')(data.la_date, "MM");
                //$scope.labelsf.push($filter('monthName')(monthNumber));
                var mun=data.number;
                //$scope.dataf.push(data.number);
                $scope.data = {
                    labels: [monthNumber],
                    datasets: [
                        {
                            label: 'My First dataset',
                            fillColor: 'rgba(220,220,220,0.2)',
                            strokeColor: 'rgba(220,220,220,1)',
                            pointColor: 'rgba(220,220,220,1)',
                            pointStrokeColor: '#fff',
                            pointHighlightFill: '#fff',
                            pointHighlightStroke: 'rgba(220,220,220,1)',
                            data: [num]
                        }

                    ]
                };
            });

but this loop gives just the last result in the JSON object I mean tis one:

{"number":1,"des":"Ceintures De Sécurités Passagères","la_date":1512134781000}

How i can get all the data please?? i have to use a push or smonrhing like that??

share|improve this question
getIncidentDepartByMonthFromTo.forEach(function(data) {

                var monthNumber=$filter('date')(data.la_date, "MM");

                var num = data.number;

                data = {
                    labels: [monthNumber],
                    datasets: [
                        {
                            label: 'My First dataset',
                            fillColor: 'rgba(220,220,220,0.2)',
                            strokeColor: 'rgba(220,220,220,1)',
                            pointColor: 'rgba(220,220,220,1)',
                            pointStrokeColor: '#fff',
                            pointHighlightFill: '#fff',
                            pointHighlightStroke: 'rgba(220,220,220,1)',
                            data: [num]
                        }

                    ]
                };
            });

you dont have to assign values to $scope.data

share|improve this answer
    
i did actually just i missed that but it doesnt work – imsi imsi Nov 7 at 13:08
    
@imsiimsi, why? – Nikhil Nov 7 at 13:09
    
i dont know why? this is my question – imsi imsi Nov 7 at 13:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.