--- id: 587d7fa8367417b2b2512bc9 title: Update the Height of an Element Dynamically required: - src: 'https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js' challengeType: 6 videoUrl: '' localeTitle: 动态更新元素的高度 --- ## Description
之前的挑战包括如何显示数组中的数据以及如何添加CSS类。您可以结合这些课程来创建简单的条形图。这有两个步骤:1)为数组中的每个数据点创建一个div 2)使用style()方法中的回调函数给每个div一个动态高度,该函数将高度设置为等于数据值。回想一下格式为使用回调函数设置样式: selection.style("cssProperty", (d) => d)
## Instructions
style()方法添加到编辑器中的代码中,以设置每个元素的height属性。使用回调函数返回数据点的值,并添加字符串“px”。
## Tests
```yml tests: - text: 第一个divheight应为12像素。 testString: 'assert($("div").eq(0).css("height") == "12px", "The first div should have a height of 12 pixels.");' - text: 第二个divheight应为31像素。 testString: 'assert($("div").eq(1).css("height") == "31px", "The second div should have a height of 31 pixels.");' - text: 第三个divheight应为22像素。 testString: 'assert($("div").eq(2).css("height") == "22px", "The third div should have a height of 22 pixels.");' - text: 第四个divheight应为17像素。 testString: 'assert($("div").eq(3).css("height") == "17px", "The fourth div should have a height of 17 pixels.");' - text: 第五个divheight应为25像素。 testString: 'assert($("div").eq(4).css("height") == "25px", "The fifth div should have a height of 25 pixels.");' - text: 第六个divheight应为18像素。 testString: 'assert($("div").eq(5).css("height") == "18px", "The sixth div should have a height of 18 pixels.");' - text: 第七个divheight应为29像素。 testString: 'assert($("div").eq(6).css("height") == "29px", "The seventh div should have a height of 29 pixels.");' - text: 第八个divheight应为14像素。 testString: 'assert($("div").eq(7).css("height") == "14px", "The eighth div should have a height of 14 pixels.");' - text: 第九个divheight应为9像素。 testString: 'assert($("div").eq(8).css("height") == "9px", "The ninth div should have a height of 9 pixels.");' ```
## Challenge Seed
```html ```
## Solution
```js // solution required ```