D3 js鼠标悬停/暂停

时间:2018-07-31 12:49:46

标签: d3.js

我可以同时使用样式填充和带有填充的类吗?

bar.selectAll("rect")
        .data(function(d) { return d.valores; })
        .enter().append("rect")
         .attr("class", function (d) { return ((d.star == true) ? "bar_star" : "bar"); }) //added line
        .attr("x", function (d) { return x1(d.name); })
        .attr("width", x1.rangeBand())
        .attr("y", height)
        .attr("height", 0)        
        .transition()
        .duration(500)
        .attr("y", function (d) { return y(d.value); })
        .attr("height", function (d) { return height - y(d.value); })
        .attr("value", function(d) { return d.name; })
        .style("fill", function(d) { return color(d.name); }); //before

bar.on("mouseover", tip.show);
bar.on("mouseout", tip.hide);

我的课程是:

.bar {
      fill: orange;
    }

.bar:hover {
  fill: orangered ;
}

如果我直接在

中尝试
  

.on(鼠标悬停)

它不起作用。我的填充不可见。当我删除该行时

  

.style(“ fill”,function(d){return color(d.name);});

工具提示或悬停都无效。我该怎么办?

感谢您的回答,

0 个答案:

没有答案
相关问题