简体   繁体   English

图表在Angular中无法正确呈现

[英]Charts not rendering properly in Angular

I've got a project that uses routing, currently with only one page. 我有一个使用路由的项目,当前只有一页。 I pass that page this controller: 我将控制器传递给该页面:

var ctrls = angular.module('controllers', []);

ctrls.controller('overviewController', function($scope){

$scope.meses = ["Enero", "Febrero", "Marzo", "Abril", "Mayo",
                "Junio", "Julio", "Agosto", "Septiembre", "Octubre",
                "Noviembre", "Diciembre"];
$scope.gastos = [0,0,0,0,0,0,0,0,0,0,0,0];
$scope.ganancias = [0,0,0,0,0,0,0,0,0,0,0,0];


});

Then, I've got a lot of inputs (two for each month, so there are 24) that work similarly to this, some aiming to "gastos" and others to "ganancias": 然后,我有很多输入(每月两次,所以有24次)与此类似,其中一些目标是“ gastos”,另一些目标是“ ganancias”:

    <div class="form-group">
      <input type="email" class="form-control" id="" placeholder="Input field" ng-model="gastos[0]">
    </div>

(ignore the type="email", it's just for a css-bootstrap rule). (忽略type =“ email”,仅用于css-bootstrap规则)。

These are my imports: 这些是我的进口:

<script src="plugins/angular-min.js"></script>
        <script src="plugins/angular-route-min.js"></script>
        <script src="plugins/chart-min.js"></script>
        <script src="plugins/angular-chart.js"></script>
        <script src="js/main.js"></script>
        <script src="js/controllers.js"></script>
        <link href="css/angular-chart.css" rel="stylesheet">
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/css.css" rel="stylesheet">

This should work, right? 这应该工作,对不对? When I load the page, I see the inputs with the 0 values from the arrays. 加载页面时,我看到了数组中值为0的输入。 If I change values on the controller, they get shown on the inputs too, so the binding works properly. 如果更改控制器上的值,它们的值也会显示在输入中,因此绑定正常工作。

Problem is, that these two charts never render, they only instantiate little white squares: 问题是,这两个图表从未渲染,它们仅实例化了小的白色方块:

 <div class="col-6-md chart-area">
    <canvas id="doughnut" class="chart chart-doughnut"
    chart-data="gastos" chart-labels="meses">
    </canvas>
    <canvas id="doughnut" class="chart chart-doughnut"
    chart-data="ganancias" chart-labels="meses">
    </canvas>
  </div>

Here you have an image to check how it actually looks: http://i.imgur.com/aY4iBsK.png (there's still a lot of work to be done, that's why the page design sucks so much!). 在这里,您有一张图像可以检查它的实际外观: http : //i.imgur.com/aY4iBsK.png (仍然有很多工作要做,这就是页面设计很烂的原因!)。

I'd love to get some help with this, since I don't understand what's happening here... 我很乐意为此提供帮助,因为我不知道这里发生了什么...

edit: 编辑:

In case you ask for the main module: 如果您要求主模块:

var main = angular.module("main", ['ngRoute', 'controllers', 'chart.js']);

main.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/overview', {
        templateUrl: 'templates/overview.html',
        controller: 'overviewController'
      }).
      otherwise({
        redirectTo: '/overview'
      });
}]);

It was just the input type="email" which was corrupting the number value. 只是输入type =“ email”破坏了数字值。 Now they render properly! 现在它们可以正确渲染了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM