{"id":7549,"date":"2015-07-26T05:12:55","date_gmt":"2015-07-26T05:12:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/07\/26\/how-to-add-a-click-event-on-nvd3-js-graph-open-source-projects-novus-nvd3\/"},"modified":"2015-07-26T05:12:55","modified_gmt":"2015-07-26T05:12:55","slug":"how-to-add-a-click-event-on-nvd3-js-graph-open-source-projects-novus-nvd3","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/07\/26\/how-to-add-a-click-event-on-nvd3-js-graph-open-source-projects-novus-nvd3\/","title":{"rendered":"How to add a click event on nvd3.js graph-open source projects novus\/nvd3"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/09188663bdcbf6a007e8fc864ca8c426?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>Alex<\/strong><\/p>\n<p>I was running into the same issue and was about to dump NVD3 all together because of the lack of documentation&#8230; What you need to do is add a callback function to addGraph(). Also note the d3.selectAll() instead of d3.select().<\/p>\n<p>Good Luck.<\/p>\n<pre><code>nv.addGraph(function() {\n     var chart = nv.models.multiBarHorizontalChart()\n         .x(function(d) { return d.label })\n         .y(function(d) { return d.value })\n         .margin({top: 5, right: 5, bottom: 5, left: 5})\n         .showValues(false)\n         .tooltips(true)\n         .showControls(false);\n\n     chart.yAxis\n         .tickFormat(d3.format('d'));\n\n     d3.select('#social-graph svg')\n         .datum([data])\n       .transition().duration(500)\n         .call(chart);\n\n       nv.utils.windowResize(chart.update);\n\n       return chart;\n     },function(){\n          d3.selectAll(\".nv-bar\").on('click',\n               function(){\n                     console.log(\"test\");\n           });\n      });\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Alex I was running into the same issue and was about to dump NVD3 all together because of the lack of documentation&#8230; What you need to do is add a callback function to addGraph(). Also note the d3.selectAll() instead of d3.select(). Good Luck. nv.addGraph(function() { var chart = nv.models.multiBarHorizontalChart() .x(function(d) { return d.label }) .y(function(d) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7549","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7549"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7549\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}