---
id: 587d7fa8367417b2b2512bcd
title: Create a Bar for Each Data Point in the Set
required:
- src: 'https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js'
challengeType: 6
videoUrl: ''
localeTitle: 为集合中的每个数据点创建一个条
---
## Description
最后一个挑战只在svg
元素中添加了一个矩形来表示一个条形。在这里,您将结合您迄今为止学习的有关data()
, enter()
和SVG形状的内容,为数据dataset
每个数据点创建和附加一个矩形。之前的挑战显示了如何为dataset
每个项目创建和附加div
的格式: d3.select( “身体”)。全选( “分区”)
。数据(数据集)
。输入()
.append( “分区”)
使用rect
元素而不是divs
有一些差异。 rects
必须附加到svg
元素,而不是直接附加到body
。此外,您需要告诉D3在svg
区域内放置每个rect
位置。酒吧安置将在下一个挑战中涵盖。
## Instructions
使用data()
, enter()
和append()
方法为dataset
每个项创建和附加rect
。条形图应该全部显示在一起,这将在下一个挑战中修复。
## Tests
```yml
tests:
- text: 您的文档应该有9个rect
元素。
testString: 'assert($("rect").length == 9, "Your document should have 9 rect
elements.");'
- text: 您的代码应该使用data()
方法。
testString: 'assert(code.match(/\.data/g), "Your code should use the data()
method.");'
- text: 您的代码应使用enter()
方法。
testString: 'assert(code.match(/\.enter/g), "Your code should use the enter()
method.");'
- text: 您的代码应使用append()
方法。
testString: 'assert(code.match(/\.append/g), "Your code should use the append()
method.");'
```
## Challenge Seed
## Solution
```js
// solution required
```