大家讲道理2017-05-15 17:03:40
Looking at the organizational structure of your code, it seems that module management is not used, so introduce d3 first and use it directly. There is no need to cover d3 in one layer, and it will not be convenient for future upgrades
<script src="lib/d3.js"></script>
<script src="lib/angular.js"></script>
Use directly
angular.module('myApp.directive', [])
.constant('d3',d3)
.directive('d3Bars', function (d3) {
return {}
});
angular.module('myApp', ['myApp.directive'])
.controller(function () {
});
If possible, it is recommended that you separate the drawing logic from your business and extract another module, such as
angular.module('ngD3', [])
.constant('d3',d3)
.directive('d3Bars', function (d3) {
return {}
});
Maybe you will contribute an awesome photo gallery in the future
黄舟2017-05-15 17:03:40
If you want to use existing wheels, I recommend you take a look at angular-nvd3. There are also examples
If you want to try it yourself, I recommend you take a look at Creating Charting Directives Using AngularJS and D3.js (you may need to bypass the wall...)