未捕获的TypeError:无法读取未定义的nvd3圆环图的属性“map”

时间:2015-12-01 23:16:44

标签: javascript angularjs d3.js nvd3.js

我有以下代码使用nvd3绘制圆环图,当我将动态objcect数组传递给datanum时,我收到了上述错误。如果我硬编码相同的对象数组格式它正在工作(绘制圆环图)。

代码:

contoller:

 $scope.getMentions = function ( ) { 
var promise = widgetServices.getMentions( );
 promise.then(function (response) { 
$rootScope.mentionsData = response.data.facet_counts.facet_pivot.toyota_series; console.log($rootScope.mentionsData); // This is $rootScope data im passing to nvd3. 
}, function (errorPayload) { $log.error('failure loading the details', errorPayload); }); } 

//Donut chart example
nv.addGraph(function() {
    var chart = nv.models.pieChart()
        .x(function(d) { return d.value })
        .y(function(d) { return d.count })
        .showLabels(true)     //Display pie labels
        //.labelThreshold(.01)  //Configure the minimum slice size for labels to show up
        .labelType("percent") //Configure what type of data to show in the label. Can be "key", "value" or "percent"
        .donut(true)          //Turn on Donut mode. Makes pie chart look tasty!
        .donutRatio(0.35)     //Configure how big you want the donut hole size to be.
    ;
    //chart.height(2000); 

    d3.select("#chart svg")
        .datum($rootScope.mentionsData)  //Dynamic data passing from controller
        .transition().duration(350)
        .call(chart);

    return chart;
});

硬编码数组:虚拟数据(图表使用此数据绘制)

exampleData =
       [
         { 

             "label": "Camry",
             "value" : 248119

         } , 
         { 

             "label": "Prius",
             "value" : 246203

         } , 
         { 

             "label": "Corolla",
             "value" : 97891

         } , 
         { 

             "label": "Tacoma",
             "value" : 57181

         } , 
         { 

             "label": "Mirai",
             "value" : 53723

         } , 
         { 

             "label": "Highlander",
             "value" : 45351

         } , 
         { 

             "label": "Tundra",
             "value" : 43394

         } , 
         { 

             "label": "4Runner",
             "value" : 38147

         },
         { 

             "label": "RAV4",
             "value" : 34563

         },
         { 

             "label": "Matrix",
             "value" : 31071

         },
         { 

             "label": "Avalon",
             "value" : 22596

         }
       ];

0 个答案:

没有答案