簡體   English   中英

Angular與D3 js

[英]Angular with D3 js

我已經通過在D3中使用eval函數動態創建了比例尺,但是當我將d3與angular一起使用時,eval函數無法正常工作,並且在我稱比例尺時出現了錯誤。

TypeError: e.copy is not a function
    at SVGGElement.<anonymous> (http://localhost:3000/app/d3.v3.min.js:5:13917)
    at http://localhost:3000/app/d3.v3.min.js:3:15103
    at Y (http://localhost:3000/app/d3.v3.min.js:1:4505)
    at Array.Co.each (http://localhost:3000/app/d3.v3.min.js:3:15078)
    at Array.n (http://localhost:3000/app/d3.v3.min.js:5:13838)
    at Array.Co.call (http://localhost:3000/app/d3.v3.min.js:3:15178)
    at Scope.HistoricalGraph.$scope.draw (http://localhost:3000/app/beanstalk/yhgraph/historicalgraph/historicalgraph.controller.js:418:26)
    at fn (eval at <anonymous> `enter code here`(http://localhost:3000/bower_components/angular/angular.js:14432:15), <anonymous>:2:203)
    at expensiveCheckFn (http://localhost:3000/bower_components/angular/angular.js:15485:18)
    at ngEventDirectives.(anonymous function).compile.element.on.callback (http://localhost:3000/bower_components/angular/angular.js:25018:17)

您可以創建一個動態對象,例如:

var channelsObject = {};
for(var i = 0;i <channel.length; i++){
  channelsObject[channel[i]] = {};
}

這樣,您將獲得如下對象:

{
   x:{},
   y:{},
   z:{}
}

人們應該始終避免使用eval。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM