我想亮點像「鮭魚」 &「獵物」,我想提供給我的詞雲,所以我應該怎麼辦字的新數組這是因爲我試圖在CSS中使用mark.js或Javascript,但無法成功,但現在我認爲只有在繪製詞雲時纔有可能。因此,有人可以幫我爲我提供了一個功能或者也許在我的代碼一些變化突出陣列的話(arrayToBeHighlight):如何突出D3詞雲詞的數組
var width = 750, height = 500;
var words = [["whales", 79], ["salmon", 56], ["Chinook", 30], ["book", 70],
["prey", 51]].map(function(d) {
return {text: d[0], size: d[1]};
});
var arrayToBeHighlight = [ ["salmon", 56], ["prey", 51] ];
**OR**
var arrayToBeHighlight = ["salmon", "prey"];
maxSize = d3.max(words, function(d) { return d.size; });
minSize = d3.min(words, function(d) { return d.size; });
var fontScale = d3.scale.linear().domain([minSize, maxSize]).range([10,70]);
var fill = d3.scale.category20();
d3.layout.cloud().size([width, height]).words(words).font("Impact")
.fontSize(function(d) { return fontScale(d.size) })
.on("end", drawCloud).start();
function drawCloud(words) {
d3.select("#wordCloud").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + (width/2) + "," + (height/2) +")")
.selectAll("text")
.data(words)
.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; });
}
HTML代碼
<div style="margin-left:20px" id="wordCloud"></div>
真棒!非常感謝。這正是我需要:) – Coder
難道你不能使用mark.js與自定義元素'rect'? – dude