当我使用Angular的指令angular-d3plus

时间:2016-09-12 17:04:36

标签: css angularjs angularjs-directive d3plus

这篇文章的后续内容是:I am trying to inject a partial template in Angular that contains a graph 基本上,我有一个Angular应用程序,当我在下拉菜单上点击“employee”时,我正在尝试注入一个名为“employees.html”的部分模板。

由于之前的答案,我可以使用Angualr控制器调用d3plus箱图(angular-d3plus.js:https://github.com/mariohmol/angular-d3plus)。我正在使用盒子演示:http://codepen.io/mariomol/pen/vGNQaV 只是为了让它第一次工作。

然而,箱形图非常微弱(我几乎无法在屏幕上看到它们):

enter image description here

通常,它们应该清晰显示:http://d3plus.org/examples/basic/78018ce8c3787d4e30d9/ 是因为我以某种方式干扰了CSS吗?

以下是我更新的employees.html:

<div data-ng-app="myModule"> 
     <div data-ng-controller="employeesController">
        <d3plus-box data="base_data" id='name' y="value" x="year"></d3plus-box>
     </div>
</div>

这是我更新的Angular模块(我正在使用测试数据):

/// <reference path="angular.min.js" />

var app = angular.module("myModule", ['ngRoute','angular-d3plus'])
                 .config(function ($routeProvider) {
                     $routeProvider
                         .when('/cases', { // Root: initialize with cases
                             templateUrl: 'templates/cases.html',
                             controller: 'casesController'
                         })
                         .when('/protocols', { // Root: initialize with cases
                             templateUrl: 'templates/protocols.html',
                             controller: 'protocolsController'
                         })
                         .when('/employees', {
                             templateUrl: 'templates/employees.html',
                             controller: 'employeesController'
                         })
                 })
                .controller('casesController', function ($scope) {
                    $scope.message = "Cases!";
                })
                .controller('protocolsController', function ($scope) {
                    $scope.message = "This is the protocols page!";
                })
                .controller('employeesController', function ($scope, $http) {
                    $http.get('dataWebService.asmx/getTotalForDateIntervalEmployees', {
                        params: { startDate: '2015-01-01', endDate: '2016-08-01' }
                    })
                    .then(function (response) {
                        $scope.base_data = [
          { "year": 1991, "name": "alpha", "value": 15, "group": "black" },
          { "year": 1991, "name": "beta", "value": -10, "group": "black" },
          { "year": 1991, "name": "gamma", "value": 5, "group": "black" },
          { "year": 1991, "name": "delta", "value": -50, "group": "black" },
          { "year": 1992, "name": "alpha", "value": 20, "group": "black" },
          { "year": 1992, "name": "beta", "value": -10, "group": "black" },
          { "year": 1992, "name": "gamma", "value": 10, "group": "black" },
          { "year": 1992, "name": "delta", "value": -43, "group": "black" },
          { "year": 1993, "name": "alpha", "value": 30, "group": "black" },
          { "year": 1993, "name": "beta", "value": -40, "group": "black" },
          { "year": 1993, "name": "gamma", "value": 20, "group": "black" },
          { "year": 1993, "name": "delta", "value": -17, "group": "black" },
          { "year": 1994, "name": "alpha", "value": 60, "group": "black" },
          { "year": 1994, "name": "beta", "value": -60, "group": "black" },
          { "year": 1994, "name": "gamma", "value": 25, "group": "black" },
          { "year": 1994, "name": "delta", "value": -32, "group": "black" }
                        ];

                    });
                });

非常感谢你的时间!

编辑:

I am trying yo make D3plus accept non-date value for boxplot and reduce space between rows in bootstrap

1 个答案:

答案 0 :(得分:1)

很高兴知道你正在使用。

在你的情况下,是不是因为你正在进行get而且.then()也必须收到错误回调?

这是使用您的代码的示例:

http://codepen.io/mariomol/pen/BLjmGV?editors=1111

<div data-ng-app="myModule"> 
 <div data-ng-controller="employeesController">
   <h1>Hello</h1>
    <d3plus-box data="base_data" id='name' y="value" x="year"></d3plus-box>
   -----------
 </div>

var app = angular.module("myModule", ['ngRoute','angular-d3plus'])
             .config(function ($routeProvider) {

                 $routeProvider
                     .when('/cases', { // Root: initialize with cases
                         templateUrl: 'templates/cases.html',
                         controller: 'casesController'
                     })
                     .when('/protocols', { // Root: initialize with cases
                         templateUrl: 'templates/protocols.html',
                         controller: 'protocolsController'
                     })
                     .when('/employees', {
                         templateUrl: 'templates/employees.html',
                         controller: 'employeesController'
                     })
             })
            .controller('casesController', function ($scope) {
                $scope.message = "Cases!";
            })
            .controller('protocolsController', function ($scope) {
                $scope.message = "This is the protocols page!";
            })
            .controller('employeesController', function ($scope, $http) {


    $http.get('http://google.com')
                .then(function (response) {

                    $scope.base_data = [
      { "year": 1991, "name": "alpha", "value": 15, "group": "black" },
      { "year": 1991, "name": "beta", "value": -10, "group": "black" },
      { "year": 1991, "name": "gamma", "value": 5, "group": "black" },
      { "year": 1991, "name": "delta", "value": -50, "group": "black" },
      { "year": 1992, "name": "alpha", "value": 20, "group": "black" },
      { "year": 1992, "name": "beta", "value": -10, "group": "black" },
      { "year": 1992, "name": "gamma", "value": 10, "group": "black" },
      { "year": 1992, "name": "delta", "value": -43, "group": "black" },
      { "year": 1993, "name": "alpha", "value": 30, "group": "black" },
      { "year": 1993, "name": "beta", "value": -40, "group": "black" },
      { "year": 1993, "name": "gamma", "value": 20, "group": "black" },
      { "year": 1993, "name": "delta", "value": -17, "group": "black" },
      { "year": 1994, "name": "alpha", "value": 60, "group": "black" },
      { "year": 1994, "name": "beta", "value": -60, "group": "black" },
      { "year": 1994, "name": "gamma", "value": 25, "group": "black" },
      { "year": 1994, "name": "delta", "value": -32, "group": "black" }
                    ];


    },function(error){

                 $scope.base_data = [
      { "year": 1991, "name": "alpha", "value": 15, "group": "black" },
      { "year": 1991, "name": "beta", "value": -10, "group": "black" },
      { "year": 1991, "name": "gamma", "value": 5, "group": "black" },
      { "year": 1991, "name": "delta", "value": -50, "group": "black" },
      { "year": 1992, "name": "alpha", "value": 20, "group": "black" },
      { "year": 1992, "name": "beta", "value": -10, "group": "black" },
      { "year": 1992, "name": "gamma", "value": 10, "group": "black" },
      { "year": 1992, "name": "delta", "value": -43, "group": "black" },
      { "year": 1993, "name": "alpha", "value": 30, "group": "black" },
      { "year": 1993, "name": "beta", "value": -40, "group": "black" },
      { "year": 1993, "name": "gamma", "value": 20, "group": "black" },
      { "year": 1993, "name": "delta", "value": -17, "group": "black" },
      { "year": 1994, "name": "alpha", "value": 60, "group": "black" },
      { "year": 1994, "name": "beta", "value": -60, "group": "black" },
      { "year": 1994, "name": "gamma", "value": 25, "group": "black" },
      { "year": 1994, "name": "delta", "value": -32, "group": "black" }
                    ];
                console.log(error);
              });

});

最好成绩