39 lines
4.3 KiB
Markdown
39 lines
4.3 KiB
Markdown
---
|
||
id: bd7168d8c242eddfaeb5bd13
|
||
title: Visualize Data with a Bar Chart
|
||
isRequired: true
|
||
challengeType: 3
|
||
videoUrl: ''
|
||
localeTitle: 使用条形图可视化数据
|
||
---
|
||
|
||
## Description
|
||
<section id="description"> <strong>目标:</strong>构建一个功能类似于此的<a href="https://codepen.io" target="_blank">CodePen.io</a>应用程序: <a href="https://codepen.io/freeCodeCamp/full/GrZVaM" target="_blank">https</a> <strong>:</strong> <a href="https://codepen.io" target="_blank">//codepen.io/freeCodeCamp/full/GrZVaM</a> 。完成以下<a href="https://en.wikipedia.org/wiki/User_story" target="_blank">用户故事</a>并通过所有测试。给它你自己的个人风格。您可以使用HTML,JavaScript,CSS和基于D3 svg的可视化库。测试需要使用D3轴属性生成轴,该属性会自动生成沿轴的刻度。通过D3测试需要这些刻度,因为它们的位置用于确定绘制元素的对齐方式。有关生成轴的信息, <a href="https://github.com/d3/d3/blob/master/API.md#axes-d3-axis" target="_blank">请</a>访问<a href="https://github.com/d3/d3/blob/master/API.md#axes-d3-axis" target="_blank">https://github.com/d3/d3/blob/master/API.md#axes-d3-axis</a> 。在每次测试时查询必需(非虚拟)DOM元素。如果您使用前端框架(例如Vue),则测试结果可能对动态内容不准确。我们希望最终能够容纳它们,但D3项目目前不支持这些框架。 <strong>用户故事#1:</strong>我的图表应该有一个标题,对应的<code>id="title"</code> 。 <strong>用户故事#2:</strong>我的图表应该有一个<code>g</code>元素x轴,对应的<code>id="x-axis"</code> 。 <strong>用户故事#3:</strong>我的图表应该有一个<code>g</code>元素y轴,对应的<code>id="y-axis"</code> 。 <strong>用户故事#4:</strong>两个轴应包含多个刻度标签,每个刻度标签对应的<code>class="tick"</code> 。 <strong>用户故事#5:</strong>我的图表应该为每个数据点都有一个<code>rect</code>元素,相应的<code>class="bar"</code>显示数据。 <strong>用户故事#6:</strong>每个栏应具有包含日期和GDP值的属性<code>data-date</code>和<code>data-gdp</code> 。 <strong>用户故事#7:</strong>条形元素的<code>data-date</code>属性应与提供的数据的顺序相匹配。 <strong>用户故事#8:</strong>条形元素的<code>data-gdp</code>属性应与提供的数据的顺序相匹配。 <strong>用户故事#9:</strong>每个条形元素的高度应准确地表示数据的相应GDP。 <strong>用户故事#10:</strong> <code>data-date</code>属性及其对应的bar元素应与x轴上的对应值对齐。 <strong>用户故事#11:</strong> <code>data-gdp</code>属性及其对应的bar元素应与y轴上的对应值对齐。 <strong>用户故事#12:</strong>我可以将鼠标悬停在一个区域上,并查看带有相应<code>id="tooltip"</code> ,其中显示有关该区域的更多信息。 <strong>用户故事#13:</strong>我的工具提示应该有一个<code>data-date</code>属性,该属性对应于活动区域的<code>data-date</code> 。以下是完成此项目所需的数据集: <code>https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json</code> : <a href="https://codepen.io/freeCodeCamp/pen/MJjpwO" target="_blank">//raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json</a>您可以通过分叉<a href="https://codepen.io/freeCodeCamp/pen/MJjpwO" target="_blank">此CodePen笔</a>来构建项目。或者您可以使用此CDN链接在您喜欢的任何环境中运行测试: <code>https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js</code> : <code>https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js</code> 。完成后,将URL提交到工作项目,并传递所有测试。如果卡住,请记住使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514" target="_blank">Read-Search-Ask</a>方法。 </section>
|
||
|
||
## Instructions
|
||
<section id="instructions">
|
||
</section>
|
||
|
||
## Tests
|
||
<section id='tests'>
|
||
|
||
```yml
|
||
tests: []
|
||
|
||
```
|
||
|
||
</section>
|
||
|
||
## Challenge Seed
|
||
<section id='challengeSeed'>
|
||
|
||
</section>
|
||
|
||
## Solution
|
||
<section id='solution'>
|
||
|
||
```js
|
||
// solution required
|
||
```
|
||
</section>
|