我想突出显示用户单击的每个术语/单词,并使用该特定术语/单词的背景框。我正在使用点击功能,我可以访问和设置单词本身的颜色,但我无法设置这个单词的背景。我怎样才能做到这一点?
这是我的绘图功能:
function draw(words) {
d3.select("#interests").append("svg")
.attr("width", w)
.attr("height", h)
.append("g")
.attr("transform", "translate(" + [w >> 1, h >> 1] + ")")
.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); })
.style("cursor", "pointer")
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; })
.on("click", function(d) {
// d3.select(this).style("fill");
d3.select(this).style("background","yellow");
if (d.inGraph == true){
d.inGraph = false;
unloadInterest(d.text);
} else {
d.inGraph = true;
loadInterest(d.text, "#ff0000");
}
});
}