# Aligning Labels to a Bar Chart with D3 - Cannot Solve

**URL:** <https://forum.freecodecamp.org/t/aligning-labels-to-a-bar-chart-with-d3-cannot-solve/349164>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [February 10, 2020, 10:22pm UTC](https://forum.freecodecamp.org/t/aligning-labels-to-a-bar-chart-with-d3-cannot-solve/349164 "2020-02-10T22:22:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marialoar](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@marialoar](https://forum.freecodecamp.org/u/marialoar)\
**Post date:** [February 10, 2020, 10:22pm UTC](https://forum.freecodecamp.org/t/aligning-labels-to-a-bar-chart-with-d3-cannot-solve/349164/1 "2020-02-10T22:22:51Z")

</div>

I cannot figure out a solution to this task, the labels seem to not align even when I follow the outline in the task.  
I’ve added a text node, and appended x and y axis for the labels which need to sit above the bars. Please see instructions in link, however, nothing seems to make it look ok.  
**Your code so far**

```html

<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", (dataset, i) => i * 30)
     .attr("y", (dataset, i) => h - 3 * dataset)
     .attr("width", 25)
     .attr("height", (dataset, i) => 3 * dataset)
     .attr("fill", "navy");

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

     // Add your code above this line
</script>
<body>

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0`.

**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:** ![sanity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanity/32/378897_2.png) [@sanity](https://forum.freecodecamp.org/u/sanity)\
**Post date:** [February 11, 2020, 4:52am UTC](https://forum.freecodecamp.org/t/aligning-labels-to-a-bar-chart-with-d3-cannot-solve/349164/2 "2020-02-11T04:52:39Z")

</div>

Currently every your label contains all values of your dataset - take a look at `.text(dataset)`. Changing this to display just single value in each label should help you with clarity and allow to tackle the proper positioning.

---

<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:** [June 1, 2021, 1:02pm UTC](https://forum.freecodecamp.org/t/aligning-labels-to-a-bar-chart-with-d3-cannot-solve/349164/3 "2021-06-01T13:02:44Z")

</div>


