词云生成器
Word Cloud Generator
我正在使用 Jason Davies's Word Cloud Generator 创建词云生成器,但它只是一种输入数据的方法 textarea 只接受 String 而我的问题是,我的数据输入是对象:
var data= [{
"text": "First",
"size": 12
}, {
"text": "Second",
"size": 35
}];
现在,这个问题有解决方案吗?
documentation is pretty clear about how it should be used. The following is adopted from the example.
var layout = cloud().words(data);
layout.start();
function draw(words) {
d3.select("#container").append("svg")
.attr("width", layout.size()[0])
.attr("height", layout.size()[1])
.append("g")
.attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
.selectAll("text")
.data(data)
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
我的问题已通过使用 Generate 函数和 Tags 数组在 [=20 中解决=].
我正在使用 Jason Davies's Word Cloud Generator 创建词云生成器,但它只是一种输入数据的方法 textarea 只接受 String 而我的问题是,我的数据输入是对象:
var data= [{
"text": "First",
"size": 12
}, {
"text": "Second",
"size": 35
}];
现在,这个问题有解决方案吗?
documentation is pretty clear about how it should be used. The following is adopted from the example.
var layout = cloud().words(data);
layout.start();
function draw(words) {
d3.select("#container").append("svg")
.attr("width", layout.size()[0])
.attr("height", layout.size()[1])
.append("g")
.attr("transform", "translate(" + layout.size()[0] / 2 + "," + layout.size()[1] / 2 + ")")
.selectAll("text")
.data(data)
.enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
我的问题已通过使用 Generate 函数和 Tags 数组在 [=20 中解决=].