Javascript 未捕获类型错误:无法读取属性';地图';未定义的nvd3甜甜圈图表
我有以下代码来使用nvd3绘制圆环图,当我将DynamicObject数组传递给datanum时,我得到了上面的错误。如果我硬编码相同的对象数组格式,它正在工作(绘制圆环图) 代码: 控制者:Javascript 未捕获类型错误:无法读取属性';地图';未定义的nvd3甜甜圈图表,javascript,angularjs,d3.js,nvd3.js,Javascript,Angularjs,D3.js,Nvd3.js,我有以下代码来使用nvd3绘制圆环图,当我将DynamicObject数组传递给datanum时,我得到了上面的错误。如果我硬编码相同的对象数组格式,它正在工作(绘制圆环图) 代码: 控制者: $scope.getMentions = function ( ) { var promise = widgetServices.getMentions( ); promise.then(function (response) { $rootScope.mentionsData = respons
$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;
});
硬编码数组:虚拟数据(用此数据绘制图表)
$rootScope.sineticsdata
是未定义的
。检查拼写并验证是否设置了值。我认为拼写没有问题。$scope.getindications=function(){var promise=widgetServices.getindications();//应通过promise传递默认日期。然后(function(response){$rootScope.indicatesdata=response.data.facet_counts.facet_pivot.toyota_series;console.log($rootScope.indicatesdata);//这是$rootScope数据,我正在传递给nvd3。},函数(errorPayload){$log.error('failure loading the details',errorPayload);});}承诺异步工作,因此在尝试访问它时可能尚未分配它。此外,你应该编辑你的问题,以包括该代码,而不是让它成为一个评论。
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
}
];