# freeCodeCamp Challenge Guide: Add Labels to Scatter Plot Circles

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-labels-to-scatter-plot-circles/301477>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [August 3, 2019, 1:06pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-labels-to-scatter-plot-circles/301477 "2019-08-03T13:06:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 3, 2019, 1:06pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-labels-to-scatter-plot-circles/301477/1 "2019-08-03T13:06:16Z")

</div>

# [Add Labels to Scatter Plot Circles](https://www.freecodecamp.org/learn/data-visualization/data-visualization-with-d3/add-labels-to-scatter-plot-circles)

* * *

## Problem Explanation

In this challenge, you are required to set the x attribute so it’s 5 units more than the value you used for the cx attribute on the circle. Set the y attribute the same way that’s used for the cy value on the circle, for the text element.

* * *

## Hints

### Hint 1

Target the `svg.selectAll("text")` codeblock.

### Hint 2

Use `d[0]` and `d[1]` for the data to be displayed.

### Hint 3

The format for display has to be `x, y`.

##### Note

There is a space between the comma and the y attribute.

* * *

## Solutions

> **Solution 1 (Click to Show/Hide)**
>
> Since, you need to add the x any y attributes similar to those as they have been set for the circle, add this to the `svg.selectAll("text")` codeblock:
> 
> ```html
> <body>
> <script>
> const dataset = [
> [34, 78],
> [109, 280],
> [310, 120],
> [79, 411],
> [420, 220],
> [233, 145],
> [333, 96],
> [222, 333],
> [78, 320],
> [21, 123]
> ];
> 
> const w = 500;
> const h = 500;
> 
> const svg = d3.select("body")
> .append("svg")
> .attr("width", w)
> .attr("height", h);
> 
> svg.selectAll("circle")
> .data(dataset)
> .enter()
> .append("circle")
> .attr("cx", (d, i) => d[0])
> .attr("cy", (d, i) => h - d[1])
> .attr("r", 5);
> 
> svg.selectAll("text")
> .data(dataset)
> .enter()
> .append("text")
> // Add your code below this line
> 
> .attr("x", (d) => d[0] + 5)
> .attr("y", (d) => h - d[1])
> .text((d) => (d[0] + ", " + d[1]))
> 
> // Add your code above this line
> </script>
> </body>
> 
> ```

---

<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 8, 2025, 3:58pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-labels-to-scatter-plot-circles/301477/2 "2025-01-08T15:58:09Z")

</div>

Closed on January 8, 2025, 3:58pm UTC


