Load JSON Data into Angular-nvD3 Graph (AngularJS)

徘徊边缘 提交于 2019-12-03 20:58:08

All you have to do is map your data once you receive it. I updated the plunker from my comment to show you how you might do this using lodash.

services.getData().then(function successCb(data) {
  $scope.data = _.map(data.data, function(prod) {
    return {
      key: prod.ID,
      y: prod.STOCK
    };
  });
});

Alternatively, if you don't want to use lodash (though it's usually included in angular applications by default), you could do something like:

$scope.data = [];
services.getData().then(function successCb(data) {
  angular.forEach(data.data, function(prod) {
    $scope.data.push({
      key: prod.ID,
      y: prod.STOCK
    });
  });
});

I think you want d3.json()

https://github.com/mbostock/d3/wiki/Requests

This command should load any JSON file. Since you're using NVD3, you should already have D3 in your project.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!