Angular JS没有渲染数据

时间:2015-02-03 12:24:00

标签: angularjs

我正在尝试使用angular-chart.js和ng-repeat创建多个图表。

PLUNKER

问题是虽然图表正在创建,但不知道为什么数据没有呈现。

HTML:

<div class="graph-display" ng-controller="jsonServerBox">
<div class="bar-chart-box" ng-repeat="module in ocw.modules"> 
<canvas class="chart chart-bar" data="module.data" labels="module.labels" series="module.series"></canvas>
</div>
</div>

JS:

(function () {
  var app = angular.module("Bar_Chart", ["chart.js", "ui.bootstrap"]);
    app.controller('jsonServerBox', function($scope) {
    var json = {"modules":[
                {
                   "series":"SeriesA",
                   "data":["90", "99", "80", "91", "76", "75", "60", "67", "59", "55"],
                   "labels":["01", "02", "03", "04", "05", "06", "07","08","09","10"],
                   "colours":[{ // default
                                  "fillColor" : "rgba(224, 108, 112, 1)",
                                  "strokeColor" : "rgba(207,100,103,1)",
                                  "pointColor" : "rgba(220,220,220,1)",
                                  "pointStrokeColor" : "#fff",
                                  "pointHighlightFill": "#fff",
                                  "pointHighlightStroke": "rgba(151,187,205,0.8)"
                                }]
                },

                {
                   "series":"SeriesB",
                   "data":["90", "99", "80", "91", "76", "75", "60", "67", "59", "55"],
                   "labels":["01", "02", "03", "04", "05", "06", "07","08","09","10"],
                   "colours":[{ // default
                                  "fillColor" : "rgba(224, 108, 112, 1)",
                                  "strokeColor" : "rgba(207,100,103,1)",
                                  "pointColor" : "rgba(220,220,220,1)",
                                  "pointStrokeColor" : "#fff",
                                  "pointHighlightFill": "#fff",
                                  "pointHighlightStroke": "rgba(151,187,205,0.8)"
                                }]
                }

        ]}; 
    $scope.ocw = json;
    });
})();

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:3)

看起来这里的数据结构是个问题。 data参数应该是系列数组的数组:

"data": [["90", "99", "80", "91", "76", "75", "60", "67", "59", "55"]],

然后它应该呈现图表。

演示: http://plnkr.co/edit/epgPgdM9I66eoP70n7Iy?p=preview

答案 1 :(得分:0)

看起来json本身存在一些问题。通过json验证器运行它并得到som错误。

修正了它们,这是输出:

{"modules":[
            {
               "series":"SeriesA",
               "data":["90", "99", "80", "91", "76", "75", "60", "67", "59", "55"],
               "labels":["01", "02", "03", "04", "05", "06", "07","08","09","10"],
               "colours":[{
                              "fillColor" : "rgba(224, 108, 112, 1)",
                              "strokeColor" : "rgba(207,100,103,1)",
                              "pointColor" : "rgba(220,220,220,1)",
                              "pointStrokeColor" : "#fff",
                              "pointHighlightFill": "#fff",
                              "pointHighlightStroke": "rgba(151,187,205,0.8)"
                            }]
            },

            {
               "series":"SeriesB",
               "data":["90", "99", "80", "91", "76", "75", "60", "67", "59", "55"],
               "labels":["01", "02", "03", "04", "05", "06", "07","08","09","10"],
               "colours":[{
                              "fillColor" : "rgba(224, 108, 112, 1)",
                              "strokeColor" : "rgba(207,100,103,1)",
                              "pointColor" : "rgba(220,220,220,1)",
                              "pointStrokeColor" : "#fff",
                              "pointHighlightFill": "#fff",
                              "pointHighlightStroke": "rgba(151,187,205,0.8)"
                            }]
            }

    ]}