Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a click event on nvd3.js graph

Tags:

I am using nvd3.js and trying to add a click event

d3.selectAll(".nv-bar").on('click', function () {console.log("test");}); 

JSFiddle

How can I do that ?

like image 939
Petran Avatar asked Jul 11 '13 16:07

Petran


1 Answers

Just found out that this works as well (at least for multibar charts):

chart.multibar.dispatch.on("elementClick", function(e) {     console.log(e); }); 

I had to look at the source in src/multibar.js to find out; since it's there, I guess this is the way it was intended to be done. However, I second what Alex said in his answer: the lack of documentation for NVD3 is a really big disadvantage. Which is sad because the general idea of the project is great: giving us the power of D3 without going into all the details...

like image 66
wexman Avatar answered Feb 13 '23 06:02

wexman