I have researched this pretty thoroughly on stackoverflow as well as the rest of the internet. The problem I am having is with d3 and having a circle change color each time the mouse is clicked.
The Idea: I have already implemented working code to add a circle each time the mouse is clicked showing where the person clicked. However, I want the color of each circle and thus each click to be different. I have looked into a toggle feature but that doesn't change the color of each circle created via each click.
Here is the code so far:
HTML:
<svg class="plot">
</svg>
CSS:
.plot
{
background-color: #000;
width: 500px;
height: 500px;
}
JavaScript:
(function() {
var svg = d3.select('svg');
function drawCircle(x, y, size) {
console.log('Drawing circle at', x, y, size);
svg.append("circle")
.style("fill","red")
.attr("cx", x)
.attr("cy", y)
.attr("r", size);
}
svg.on('click', function() {
var coords = d3.mouse(this);
console.log(coords);
drawCircle(coords[0], coords[1], 5);
});
})();
Any help would be great! Also here is the jsfiddle link: https://jsfiddle.net/pwilliams/2yczn6q3/