var bar = chart.selectAll("g")
.data(data)
.enter()
.append("g")
.attr("transform", function(d, i) {
return "translate("+barWidth*i+",0)";
})
.on("mouseover", function() {
d3.select(this)
.attr("fill", "red");
})
.on("mouseout", function(d, i) {
d3.select(this)
.attr("fill", "blue");
});
我正在尝试使用鼠标悬停来显示数据。我首先尝试按照上面的代码更改鼠标悬停的颜色。
答案 0 :(得分:1)
以下是解决方案:
.on("mouseover", function() {
d3.select(this).select('rect').style('fill', 'red');
})
.on("mouseout", function(d, i) {
d3.select(this).select('rect').style('fill', 'blue');
});
您需要选择元素中的形状和样式函数来更改颜色。
答案 1 :(得分:1)