1

How to add onclick event for each node of scatter chart of NVD3. see the example

Please help.

jones
  • 1,423
  • 3
  • 35
  • 76
  • possible duplicate of [How to add a click event on nvd3.js graph](http://stackoverflow.com/questions/17598694/how-to-add-a-click-event-on-nvd3-js-graph) – shabeer90 Aug 12 '15 at 08:46
  • Not a duplicate as the point onClick is much different than bars, unfortunately. – Scott Skiles Mar 05 '19 at 21:30

2 Answers2

2

I prefer Using D3 Dispatch Event

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

Similar Question(Bar Chart)

API Documents Are Getting Better NVD3 API

Community
  • 1
  • 1
jawadhoot
  • 164
  • 1
  • 7
0

I am not sure if there is a direct way to accomplish this using NVD3, but I had a similar issue before.

I used the d3.selectAll(), add this code once after the chart is loaded.

d3.selectAll("#chart svg path").on('click', function (e) {
    console.log(e); // Do your stuff here
});

Returns an object like the following when you click on a point

Object {data: Array[4], series: 3, point: 27}

Hope it helps

shabeer90
  • 5,161
  • 4
  • 47
  • 65