2018-09-30 23:01:58 +01:00
---
id: 587d7fab367417b2b2512bd7
title: Create a Scatterplot with SVG Circles
challengeType: 6
2019-08-05 09:17:33 -07:00
forumTopicId: 301484
2021-01-13 03:31:00 +01:00
dashedName: create-a-scatterplot-with-svg-circles
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
A scatter plot is another type of visualization. It usually uses circles to map data points, which have two values each. These values tie to the `x` and `y` axes, and are used to position the circle in the visualization.
SVG has a `circle` tag to create the circle shape. It works a lot like the `rect` elements you used for the bar chart.
# --instructions--
Use the `data()` , `enter()` , and `append()` methods to bind `dataset` to new `circle` elements that are appended to the SVG canvas.
**Note**
The circles won't be visible because we haven't set their attributes yet. We'll do that in the next challenge.
# --hints--
Your code should have 10 `circle` elements.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert($('circle').length == 10);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
```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 ]
];
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
const w = 500;
const h = 500;
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
const svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
svg.selectAll("circle")
// Add your code below this line
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
// Add your code above this line
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< / script >
< / body >
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2020-04-24 17:04:53 +05:30
```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")
< / script >
< / body >
2018-09-30 23:01:58 +01:00
```