【发布时间】:2016-08-25 16:59:34
【问题描述】:
https://plnkr.co/edit/vE5Km2?p=preview
我想用 angular-nvd3 以角度呈现 d3 饼图。我没有错误,所有相关的脚本都在加载。
我不确定如何调用指令内的函数—— 提供的指令是:
<nvd3 options='options' data='data'></nvd3>
我改成了:
<nvd3 options='vm.options' data='vm.data'></nvd3>
HTML:
<div ng-controller='MainController'>
<nvd3 options='vm.options' data='vm.data'></nvd3>
</div>
main.controller:
(function (angular) {
'use strict';
angular
.module('blah').controller('MainController', MainController);
function MainController () {
var vm = this;
vm.initSampleData = initSampleData; // set up the var
function initSampleData() {
vm.options = {
'chart': {
'type': 'pieChart',
'height': 500,
'showLabels': true,
'duration': 500,
'labelThreshold': 0.01,
'labelSunbeamLayout': true,
'legend': {
'margin': {
'top': 5,
'right': 35,
'bottom': 5,
'left': 0
}
}
}
};
vm.data = [
{key: 'One', y: 5},
{key: 'Two', y: 2},
{key: 'Three', y: 9},
{key: 'Four', y: 7},
{key: 'Five', y: 4},
{key: 'Six', y: 3},
{key: 'Seven', y: .5}
];
}
}
})(window.angular);
如果我添加路线(不使用指令,为 Angular 2.0 做好准备) MainRoute.$inject = ['$routeProvider', 'nvd3'];它错误...
function MainRoute($routeProvider){
$routeProvider.when('/', {
controller: 'MainController as vm',
templateUrl : 'main.html',
bindToController: false
});
}
【问题讨论】:
标签: javascript angularjs d3.js nvd3.js