2016-03-06 54 views
2

这里是我做的:D3事件不工作

var path = svg.selectAll(".arc") 
    .data(pie(data).sort(null)) 
    .enter().append("g") 
    .attr("class", "arc") 
    .append("path").style("stroke-width", 0) 
    .on("click", function(d){console.log(d)}) 
    .style("stroke", "white") 
    .attr("d", arc) 
    .style("fill", color) 
    .style("opacity", function(d){ return(d.data.name == "ess")?0.6:1}) 
    .on("mouseover", function(d,i){ alert(1);}) 
    .on("mouseout", animateSecondStep); 

但这些事件被解雇

This is what i get in events

这里的jsfiddle https://jsfiddle.net/4pmdaaaz/1/

+0

你有一个小提琴,我们可以看到什么? – thatOneGuy

+0

@thisOneGuy对不起,完全忘了它。 https://jsfiddle.net/4pmdaaaz/1/ –

回答

2

看起来像此行:

document.getElementById(element).innerHTML += "<div class='result visible'><div class='giant-text' style='font-size:32px;'>" + precentage + "%</div> </div>"; 

搞乱了互动。没有它的工作,更新小提琴:https://jsfiddle.net/reko91/4pmdaaaz/3/

它是由于您更改元素为'第一个',这是饼图的容器的元素innerHTML。我绝对推荐不要使用innerHTML,而是使用textContent。但是,在这种情况下,我建议做一个新的div并改变div的风格展现,在这种情况下,33%:)

希望帮助

+1

OMG。非常感谢。我将其更改为appendChild并且它可以正常工作。再次感谢。 –

+0

没问题:))很高兴我能帮上忙。我建议与其他例子进行比较,看看你的代码和他们的代码有什么不同。更容易发现错误:) – thatOneGuy