Convert json data to angularjs module into array and graph using c3 chart

I would like to generate an xy plot based on JSON feed using angle characters. JSON data is shown in the code below (VQ equalizer time). How can I convert this data to an array format and build it in the c3 table (for example, in this link http://c3js.org/samples/data_json.html )?

Many thanks for your help.

var array1 = [];    
var app = angular.module('myApp',[]);
app.controller('eqfeed',function($scope,$http){
    $http.get("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson").then(function(response) {
        $scope.eq=response.data.features;
        });
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    
<body>
<div ng-app="myApp" ng-controller="eqfeed">
<table>
    <tr ng-repeat="x in eq">
        <td>{{x.properties.time | date:'yyyy-MM-dd HH:mm:ss'}}</td>
        <td>{{x.properties.mag}}</td>
    </tr>
</table>    
</div>     
    
</body>    
</html>
Run codeHide result
+4
source share
1 answer

This seems to be a duplicate. You just need to get the data and define the x axis as time periods.

var chart = c3.generate({
        data: {
            x: "time",
            json: {
                time: eq.properties.time,
                data: eq.properties.mag
            }
        },
        axis:{
            x:{
                type: "timeseries",
                tick:{
                    format:"%Y-%m-%d %H:%M:%S"
                }
            }
        }
    });

html .

<div id="chart"></div>
+1

Source: https://habr.com/ru/post/1659948/


All Articles