admin管理员组文章数量:1317909
I'm using nvd3.js with line and line-with-focus charts for a project. There is a requirement to bind data and events to the xAxis tick elements. I've been trying in vain to bind events to a single line manually through the console.
// try to bind to the first xAxis <line> in my line-with-focus chart
d3.select( 'div#problem-chart .nv-focus .nv-x .tick line' )
.on( 'mouseover', function( e ){
console.log( e );
} )
I've even set chart.interactive( false )
to make sure there is no interactive layer that captures events and kills them. Has anyone managed to bind events to the xAxis or have guesses on why the above is not working?
I'm using nvd3.js with line and line-with-focus charts for a project. There is a requirement to bind data and events to the xAxis tick elements. I've been trying in vain to bind events to a single line manually through the console.
// try to bind to the first xAxis <line> in my line-with-focus chart
d3.select( 'div#problem-chart .nv-focus .nv-x .tick line' )
.on( 'mouseover', function( e ){
console.log( e );
} )
I've even set chart.interactive( false )
to make sure there is no interactive layer that captures events and kills them. Has anyone managed to bind events to the xAxis or have guesses on why the above is not working?
-
Did you check if you're actually selecting something? It looks like your selector should be something like
div#problem-chart > .nv-focus > .nv-x > .tick > line
. – Lars Kotthoff Commented Feb 27, 2014 at 18:11 - @LarsKotthoff: yes, i checked that. It is actually selecting something – sudobangbang Commented Feb 27, 2014 at 18:14
-
@LarsKotthoff: it seems to be that sub elements of
g.nv-linesWrap
are capturing events and those events are not percolating to theg.nv-focus
children. ugh – sudobangbang Commented Feb 27, 2014 at 19:06 -
Hmm, I supposed you could select those elements and set
pointer-events: none
on them. – Lars Kotthoff Commented Feb 27, 2014 at 19:08
1 Answer
Reset to default 10You have to explicitly set the pointer-events property on the lines so they will respond to mouse events:
d3.selectAll('g.nv-axis line')
.style("pointer-events", "visiblePainted")
.on("mouseover", function(){
d3.select(this).style("stroke", "red");
});
There's a CSS style rule turning off all pointer events on the axis ponents:
.nvd3 .nv-axis {
pointer-events: none;
}
I had a heck of a time tracking it down, though -- the Chrome DOM inspector doesn't show it as an "inherited" style on the individual ticks even though it affects them.
本文标签: javascriptNVD3js bind hoverclick events to the xAxis tick ltlinegtStack Overflow
版权声明:本文标题:javascript - NVD3.js bind hoverclick events to the xAxis tick <line> - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742028202a2415952.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论