This should be a multilinegraph i have an array like this as data:
data = [[point:{x: 0, y: 1},point:{x: 0, y: 3}], [point:{x: 3, y: 1},point:{x: 3, y: 3}], [point:{x: 0, y: 6},point:{x: 1, y: 9}], [point:{x: 2, y: 6},point:{x: 3, y: 2}]]
code:
gr.line = d3.line()
.x((d) => d.point.x)
.y((d) => d.point.y)
let allGroup = gr.g.selectAll(".pathGroup").data(data)
allGroup.exit().remove()
let g = allGroup.enter()
.append("g")
.attr("class", "pathGroup")
g.append("path")
.attr("class", "line")
.attr("stroke", (d) => {
return 'red'
})
.attr("d", (d) => gr.line(d))
I want to add circles to the path. If i want to append circles to the group (in this case the variable g), i get the whole array. But i just need each item from the array to append the circle. I want to do it with data binding because i want to remove the items if the data changes. I get it done with forEach loop but i think is not a good solution. Somebody has an idea how to get it done with data binding?
.attr("d", (d) => gr.line(d))is the same of.attr("d", gr.line).