# Adding Labels to D3 Elements

**URL:** <https://forum.freecodecamp.org/t/adding-labels-to-d3-elements/258443>\
**Category:** General\
**Created:** [February 12, 2019, 6:09pm UTC](https://forum.freecodecamp.org/t/adding-labels-to-d3-elements/258443 "2019-02-12T18:09:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aledgriffiths79](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@aledgriffiths79](https://forum.freecodecamp.org/u/aledgriffiths79)\
**Post date:** [February 12, 2019, 6:09pm UTC](https://forum.freecodecamp.org/t/adding-labels-to-d3-elements/258443/1 "2019-02-12T18:09:37Z")

</div>

**Tell us what’s happening:**

Hello, cant find the answer, can someone tell me what it is and explain in basic simplified form as im new to all this, thanks

**Your code so far**

```auto

<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")
       .data(dataset)
       .enter()
       .append("rect")
       .attr("x", (d, i) => i * 30)
       .attr("y", (d, i) => h - 3 * d)
       .attr("width", 25)
       .attr("height", (d, i) => 3 * d)
       .attr("fill", "navy");
    
    svg.selectAll("text")
       .data(dataset)
       .enter()
       .append("text")
       .attr("x", (d, i)=> i * 30)
       .attr("y", (d, i)=> (h-3*d)-3)
       .text()
       // Add your code below this line
       
       
       
       
       // Add your code above this line
  </script>
<body>

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36`.

---

<div class="post-metadata">

**Author:** ![shimphillip](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/shimphillip/32/158663_2.png) [@shimphillip](https://forum.freecodecamp.org/u/shimphillip)\
**Post date:** [February 12, 2019, 7:58pm UTC](https://forum.freecodecamp.org/t/adding-labels-to-d3-elements/258443/2 "2019-02-12T19:58:30Z")

</div>

Hey you are kind of getting there.

Make sure you are giving width, height and text like the above `svg.selectAll("rect")` does.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:05pm UTC](https://forum.freecodecamp.org/t/adding-labels-to-d3-elements/258443/3 "2021-01-17T20:05:33Z")

</div>

Closed on January 17, 2021, 8:05pm UTC


