https://plnkr.co/edit/vE5Km2?p=preview
I want to render an d3 pie chart in angular with angular-nvd3. I have no errors and all of the associated scripts are loading.
I'm not sure how to call the function inside of the directive-- The supplied directive is:
<nvd3 options='options' data='data'></nvd3>
which I changed to:
<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);
Route (not using directive, getting ready for angular 2.0) if i add MainRoute.$inject = ['$routeProvider', 'nvd3']; it errors...
function MainRoute($routeProvider){
$routeProvider.when('/', {
controller: 'MainController as vm',
templateUrl : 'main.html',
bindToController: false
});
}