我正在使用来自http://www.jasondavies.com/wordcloud/#http%3A%2F%2Fen.wikipedia.org%2Fwiki%2F%7Bword%7D=cloud的d3示例来构建我自己的单词云.
我想要做的就是根据单词表示的对象的属性为单词添加一些颜色属性.
例如,有4个单词 - 美国,印度,英国和德国 - 我使用阈值来设置单词的颜色 - 让我们说这更像是根据人口密度设置颜色.
然而,这绝不会影响字体的大小 - 这可能表示该国的土地面积.
我的问题是这些单词彼此重叠.
我想知道我做错了什么 - 看看这段代码 - 我的'画'功能.我在这里做错了什么?
draw: function(countries) {
var cctrplt = {BuOrPuRd: {
4: ["#9ebcda","#e32636","#08306b", "#ffbf00"]
}};
var fillthr =
d3.scale.threshold()
.domain([2, 5, 10])
.range(cctrplt.BuOrPuRd[4]);
d3.select("#ddTagCloudContentRoot").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(300,300)")
.selectAll("text")
.data(countries)
.enter().append("text")
.style("font-size", function(d) { return (d.size) + "px"; })
.style("font-family", "Impact")
.style("fill", function(k,i) { var ccode = colours_list[k.text]; return fillthr(ccode); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, …
Run Code Online (Sandbox Code Playgroud)