# Add labels to D3 solution

**URL:** <https://forum.freecodecamp.org/t/add-labels-to-d3-solution/534322>\
**Category:** freeCodeCamp Contributors\
**Tags:** contributing\
**Created:** [July 25, 2022, 8:18pm UTC](https://forum.freecodecamp.org/t/add-labels-to-d3-solution/534322 "2022-07-25T20:18:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![augsaba](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/augsaba/32/250769_2.png) [@augsaba](https://forum.freecodecamp.org/u/augsaba)\
**Post date:** [July 25, 2022, 8:18pm UTC](https://forum.freecodecamp.org/t/add-labels-to-d3-solution/534322/1 "2022-07-25T20:18:26Z")

</div>

**What is your hint or solution suggestion?**  
/ **Instead of changing rectangle y coordinate and height by 3 times of d we can change it by 2 times then the result is available clearly on screen.** /  
svg.selectAll(“rect”)  
.data(dataset)  
.enter()  
.append(“rect”)  
.attr(“x”, (d, i) =\> i \* 30)  
.attr(“y”, (d, i) =\> h - 2 \* d)//change y by 2 times  
.attr(“width”, 25)  
.attr(“height”, (d, i) =\> 2 \* d)//change height by 2 times  
.attr(“fill”, “navy”);

```
svg.selectAll("text")
   .data(dataset)
   .enter()
   // Add your code below this line
   .append("text")
  .attr("x",(d,i)=> i * 30)
   .attr("y",(d,i)=>h-2*d)
   .text((d,i)=>d)

```

**Challenge:** Add Labels to D3 Elements

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/data-visualization/data-visualization-with-d3/add-labels-to-d3-elements)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [January 24, 2023, 8:18am UTC](https://forum.freecodecamp.org/t/add-labels-to-d3-solution/534322/2 "2023-01-24T08:18:59Z")

</div>

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