D3 is skipping values

Trying to finish the D3 Scatter Plot graph question but there is an issue with D3 showing all the values on the graph as I am selecting all circles and entering data values.

link to code

Please help me to resolve this issue.

Update: Ok so now the issue is resolved.

Initially, I was selecting all the circles i.e svg.selectAll(“circles”), and this way it was skipping 2 values (index 0, 1).

Then I changed it to svg.selectAll(".dot") and it is working fine.

Can someone explain this, please?

This is because of the way selectAll method works.

When you call it on selection it selects the descendant elements that match the specified selector string.

selection.selectAll(selector)

Therefore, the code below will select on all the descendant elements of the svg, including the two circle elements that make up your legend.

svg.selectAll("circle")

Here’s a link to the documentation about selectAll method.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.