我正在尝试使用angularJS和nvD3生成条形图。我的控制器是这样的:
function initMyController(fac, $scope, DATA_URL, $http){
$http.get(DATA_URL).success(function(response){
console.log(response);
var values = [];
$scope.data = [];
angular.forEach(response, function(item) {
//in my response I have the correct values
values.push({'label:' : item.label, 'value:' : item.value});
});
$scope.data = values;
});
}
在视图上我有这个
<div ng-controller="MyCtrl">
<nvd3 options="options"
data="data"
config="config"
events="events"
api="api"></nvd3>
</div>
但是在尝试渲染图形时我总是遇到这个错误。
TypeError: Cannot read property 'length' of undefined
at http://localhost:9000/bower_components/nvd3/nv.d3.js:3684:78
at Array.filter (native)
at SVGSVGElement.<anonymous> (http://localhost:9000/bower_components/nvd3/nv.d3.js:3684:42)
at http://localhost:9000/bower_components/d3/d3.js:8114:14
at d3_selection_each (http://localhost:9000/bower_components/d3/d3.js:888:30)
at Array.d3_transitionPrototype.each (http://localhost:9000/bower_components/d3/d3.js:8112:7)
at Array.chart (http://localhost:9000/bower_components/nvd3/nv.d3.js:3664:15)
at Array.d3_selectionPrototype.call (http://localhost:9000/bower_components/d3/d3.js:895:14)
at Object.link.scope.api.updateWithData (http://localhost:9000/bower_components/angular-nvd3/dist/angular-nvd3.min.js:1:5556)
at Object.link.scope.api.updateWithOptions (http://localhost:9000/bower_components/angular-nvd3/dist/angular-nvd3.min.js:1:4752)
(anonymous function)
$get
$get.Scope.$digest
scopePrototype.$digest
$get.Scope.$apply
scopePrototype.$apply
done
completeRequest
requestLoaded
我错过了什么?