我计划使用d3-cloud来生成一个单词云,并尝试在rails应用程序中使用它,如下所示。我是d3和backbone的初学者,如果这个问题很愚蠢,请原谅。
来自https://github.com/jasondavies/d3-cloud/blob/master/examples/simple.html
我一直收到这个错误,没有捕获到TypeError:对象呈现没有方法'apply‘
我的Api返回结果如下。
{"text":"Timmy Doe","size":100},{"text":"John Doe","size":50}
class Mongoauth.Views.TagCloud extends Backbone.View
id = 0
defaults: {
w: 1,
h: 5
}
initialize:->
_.bindAll(this,"render");
@collection.bind("reset",this.render);
@collection.bind("change", this.render);
this.chart = d3.layout.cloud().size([300, 300]).words(@collection.models).padding(5).rotate(->
~~(Math.random() * 2) * 90
).font("Impact").fontSize((d) ->
d.size
).on("end", "render").start()
# this.chart = d3.select(this.el).append('svg').attr("width", 300)
# .attr("height", 200)
# .attr("viewBox","0 0 100 100");
console.log(@collection)
render: ->
d3.select(this.el).append("svg").attr("width", 300).attr("height", 300).append("g").attr("transform", "translate(150,150)").selectAll("text").data(this.collection.models).enter().append("text").style("font-size", (d) ->
d.size + "px"
).style("font-family", "Impact").style("fill", (d, i) ->
d3.scale.category20() i
).attr("text-anchor", "middle").attr("transform", (d) ->
"translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")"
).text (d) ->
d.text
this发布于 2013-09-07 14:33:11
您在.on("end", "render").start()行上传递了一个字符串作为事件侦听器。它需要是一个函数引用(比如this.render)。
https://stackoverflow.com/questions/18669559
复制相似问题