This is the code for the Sankey diagram, The first time I added the this when creating node. It is not working.
.on("click", function (d) {
console.log(d);
})
Then I commented d3.behavior.drag()
, Then it worked.
This will work.
var node = svg.append("g").selectAll(".node")
.data(energy.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.on("click", function (d) {
console.log(d);
});
// .call(d3.behavior.drag()
// .origin(function(d) { return d; })
// .on("dragstart", function() { this.parentNode.appendChild(this); })
// .on("drag", dragmove));
This will not work.
var node = svg.append("g").selectAll(".node")
.data(energy.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.on("click", function (d) {
console.log(d);
})
.call(d3.behavior.drag()
.origin(function(d) { return d; })
.on("dragstart", function() { this.parentNode.appendChild(this); })
.on("drag", dragmove));
Can someone tell why? How can I add onclick event?
Thanks for your help!!!