gpt4 book ai didi

javascript - 将angularjs模块中的json数据转换为数组并使用c3图表绘制

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:27:13 24 4
gpt4 key购买 nike

我想使用 angularjs 基于 JSON 数据提要生成 x-y 图。JSON 数据显示在下面的代码中(EQ 幅度 VS 时间)。如何将此数据转换为数组格式并将其绘制在 c3 图表中(例如此链接中的图表 http://c3js.org/samples/data_json.html )?

非常感谢您的帮助。

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>

最佳答案

这似乎是一个 duplicate .您只需获取数据并将 x 轴定义为时间序列。

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>

关于javascript - 将angularjs模块中的json数据转换为数组并使用c3图表绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40442212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com