D3 create and append a rect

Tell us what’s happening:
Describe your issue in detail here.
Hi,
I have to ceate and append a rectangle for each item of the dataset. My code doesn’t seem to work, I don’t understand why. Anyone could help me please ? Thanks.

  **Your code so far**

<body>
<script>
  const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];

  const w = 500;
  const h = 100;

  const svg = d3.select("body")
                .append("svg")
                .attr("width", w)
                .attr("height", h);

  svg.selectAll("rect")
     // Add your code below this line
.data(dataset)
.enter()
.append("rect");



     // Add your code above this line
     .attr("x", 0)
     .attr("y", 0)
     .attr("width", 25)
     .attr("height", 100);
</script>
</body>
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0

Challenge: Create a Bar for Each Data Point in the Set

Link to the challenge:

What do you mean by not working? To clarify, the code will create multiple rect but they are displayed on top of each other. The next challenge will make them appear at different locations.

Alright, thank you for your help :slightly_smiling_face:

1 Like

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