Absolutely, it is possible to do so. However, it is recommended to utilize the attr
method for manipulating DOM values and the style
method for handling CSS properties.
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.style("r", 3)
.attr("cx", function(d) {
return x(d.date);
})
.attr("cy", function(d) {
return y(d.value);
})
.attr("stroke", function(d) {
return color(this.parentNode.__data__.name)
})
.attr("fill", function(d) {
return color(this.parentNode.__data__.name)
})
Take a look at this example showcasing the usage of style
, and compare it with this example which uses attr
. Both methods achieve similar results, but observing the DOM structure
can be insightful.
When utilizing attr
:
`<circle class="dot" r="3" cx="0" cy="174.375" stroke="#1f77b4" fill="#1f77b4"></circle>`
Using style
:
`<circle class="dot" cx="0" cy="174.375" stroke="#1f77b4" fill="#1f77b4" style="r: 3;"></circle>`