我没有在标题中正确解释这个问题...抱歉.
我正在关注D3 Tag Cloud简单示例 https://github.com/jasondavies/d3-cloud/blob/master/examples/simple.html
我有一个JSON文件,包含推文标签,感情值和推文文本; (摘抄)
var words = [{"word":"disgrace","sentiment":"0.975","tweet":"Wheres Fred the weatherman? \nIn jail #disgrace #dirtyman @MrJimmyCorkhill"},{"word":"dirtyman","sentiment":"0.975","tweet":"Wheres Fred the weatherman? \nIn jail #disgrace #dirtyman @MrJimmyCorkhill"}];
Run Code Online (Sandbox Code Playgroud)
我想使用"tweet"值作为每个"text"元素的"title"元素.我尝试将我的推文放在.words函数(或.map,我不知道:s)中,因为其他数据是以这种方式访问的,但我无法提取我的'tweet'数据;
var fill = d3.scale.category20();
var words = <?php echo $tweets->getTweetTags(); ?>;
d3.layout.cloud().size([1000, 1000])
.words(words.map(function(d) {
return {text: d.word, size: d.sentiment * 40, tweet: d.tweet};
}))
.rotate(function() { return ~~(Math.random() * 2) * Math.random() * 1; })
.font("Impact")
.fontSize(function(d) { return d.size; })
.on("end", draw)
.start();
function draw(words) {
d3.select("#vis").append("svg")
.attr("width", 1000)
.attr("height", …Run Code Online (Sandbox Code Playgroud) d3.js ×1