Another obscure nvd3 question, this time with onClick
.
I was able to use this question to figure out how to add an "onClick" event for bars using nvd3's linePlusBarChart.
The jsfiddle here is working. Please feel free to click on a bar to see what I'm going for (using alert
as a test). The relevant code is at the bottom of the JavaScript, also shown here:
d3.select('#chart1 svg')
.datum(testdata)
.transition().duration(500).call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
return chart;
}, function(){
d3.selectAll(".nv-bar").on('click',
function(e){
console.log(e);
alert("You clicked on bar!");
}
);
});
This is really great! I am really happy with this as a solution. Using function(e)
to get data from the NVD3 bar I can then use the bar data (quantity and date) to do other cool things with JavaScript.
Unfortunately, I discovered that if I use the bottom panel to zoom in on a specific date range the 'onClick' event stops working.
What is happening that causes the onClick
event to become disassociated with a specific bar?
Is there an additional location that I need to add the onClick
logic?
Any help would be greatly appreciated.