ElasticSearch to NVD3 in Angularjs
ElasticSearch to NVD3 in Angularjs
我正在尝试将数据从 Angularjs 中的 ES 查询传递到 NVD3 以进行可视化,但我是 JS 的新手并试图弄清楚。 我看到它需要一个带有 k/v 对的数组,但是如何将返回的数据转换为该格式?
我的查询:
esClient.search({
index: 'unitedstates',
size: 5,
body: {
query: {
"match_all" : {}
},
facets: {
tagcloud: {
terms: {
field: 'state'
}
}
}
}
}).then(function (resp) {
$scope.data = resp.facets.tagcloud.terms;
});
结果:
Array[10]
0: Object
count: 986
term: "virginia"
__proto__:
Object1:
Object2:
Object3:
Object4
从NVD3开始,他们希望以以下形式从网站(http://nvd3.org/examples/pie.html)
return [
{
"label": "One",
"value" : 29.765957771107
} ,
{
"label": "Two",
"value" : 0
} ,
{
"label": "Three",
"value" : 32.807804682612
} ,
{
"label": "Four",
"value" : 196.45946739256
} ,
{
"label": "Five",
"value" : 0.19434030906893
} ,
{
"label": "Six",
"value" : 98.079782601442
} ,
{
"label": "Seven",
"value" : 13.925743130903
} ,
{
"label": "Eight",
"value" : 5.1387322875705
}
];
如果我理解正确,你可以这样做
$scope.data = [];
for (var i=0; i<resp.length; ++i) {
$scope.data.push({
label: resp[i].term,
value: resp[i].count
});
}
相关文章:
- Instagram oauth flow in angularjs
- AngularJS.Filter in ng中的多个条件重复
- angularjs formly submit bug in safari & IE 11
- 如何获得家长's的父's的父's id in Angularjs
- 进度条与 ngRoute in angularjs.
- Jquery in AngularJs
- ng-class not working properly in 'AngularJs'
- AngularJS-ngRepeat对对象的返回顺序与vanillar.in循环不同
- AngularJs: ng-repeat="item in arrayValue"
- AngularJS promise in app.run()
- limitTo not working in ng-repeat in AngularJs
- AngularJS "localStorage.getItem" is null in $resou
- ElasticSearch to NVD3 in Angularjs
- Angularjs with dynamic model in ng-repeat
- Defer 和 Promise in angularjs 无法正常工作
- Angularjs in sharepoint 365
- Angularjs in rails:在不重新加载的情况下更改页面
- Shortening for AngularJS in javascript
- Angularjs in rails:添加数据到数据库并显示,而不需要重新加载
- AngularJS in Confluence