JS and drawing circles, I am dragging it to certain coordinates, now I need to retrieve x-cordinate, y-coordinate and colour(which I am assigning randomly) of selected Item, I am able to get x-cord, y-cord, radius but colour is showing null. Here I am assigning colour and coordinate:
svg.selectAll("circle")
.data(circles)
.enter().append("circle")
.attr("cx", function (d) {
return d.x;
})
.attr("cy", function (d) {
return d.y;
})
.attr("r", radius)
.style("fill", function (d, i) {
return color(i);
})
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));
here I am trying to retrieve coordinate and colour of selected item
function dragended(d) {
d3.select(this).classed("active", false);
console.log('dragged ' + flagForCircle + ' xCord ' + d3.select(this).attr('cx')+' ycord ' + d3.select(this).attr('cy') +' color ' + d3.select(this).attr('fill'));
d3.select(this).on('mousedown.drag', null);
}
}