使用Plotly和AngularJS绘制REST API响应
Plot REST API response using Plotly and AngularJS
如何从json {month,consumption}中分配a和b值?
REST API响应:
data= {
"_id": {
"$oid": "580b8f80c2ef1645d285c884"
},
"year": "2012",
"state": "Indiana",
"consumption": 3275,
"month": "january"
},
{
"_id": {
"$oid": "580b8f81bd966f4110af0111"
},
"year": "2012",
"state": "Indiana",
"consumption": 6348,
"month": "february"
}
app.js:
var graphPlotterDemoApp = angular.module('graphPlotterDemoApp', ['graphPlotter']);
graphPlotterDemoApp.controller('graphPlotterDemoCtrl', function($scope, $http) {
var a = ["jan", "feb", "mar", "apr"];
var b = [10, 15, 13, 17];
$scope.data={};
$scope.refresh = function(){
$http.get("https://api.mlab.com/api/1/databases/energyx/collections/energydata_2012?&apiKey=6JzRAzvdeqyLKAfQAqMOsLYLvvIdJG6A")
.success(function(response) {
$scope.data = response.data;
});
};
var trace1 = {
x: a,
y: b,
type: 'scatter'
};
$scope.refresh();
$scope.graphPlots = [trace1];
});
使用like从json中获取数据
var a=$scope.data.map(function(a) {return a.month;})
var b=$scope.data.map(function(a) {return a.consumption;})
相关文章:
- Amazon S3 REST API大小不正确
- 客户端服务器REST API captcha实现
- 在同一ip但不同端口上使用Rest API
- 从ANGULAL连接到REST API
- 如何在使用loopback REST API时更改gulp-angular项目的端口号
- Cross domain - REST API
- 更改REST API服务器的最佳实践
- DreamFactory REST API POST休息/用户/会话请求总是在IE9中返回错误
- REST API node.js
- 数据未显示 - 余烬 js - Rest API
- 登录后无法使用 ACS REST API 发送推送通知
- 在 Rest API 中发布调用
- REST API 服务器是否应该使用 PUT 接收 JSON 数据或普通表单数据
- 如何使用已经存在的 REST API 后端在 Angular 应用程序中实现登录系统
- 获取文件并从rest api下载
- 使用Angular Resource查询具有字符串参数的REST API
- Visual Studio Team Services Rest API未授权的客户端错误
- 无法通过rest api读取json变量
- Wordpress REST API身份验证,无需登录页面
- 通过REST API/GET请求订阅Mailchimp列表