4

I would like to generate an x-y plot based on a JSON data feed using angularjs. The JSON data is shown in the code below (EQ magnitude VS time). How can I convert this data into an array format and plot it in c3 chart (such as one in this link http://c3js.org/samples/data_json.html)?

Thank you very much 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>

1 Answer 1

1

This seems to be a duplicate. You just have to get the data and define your x-axis as a timeseries.

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"
                }
            }
        }
    });

And in your html you only have to get your chart.

<div id="chart"></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.