* Guide to the Data Visualization with D3 Work with Data in D3 * Guide to data visualization with d3 work with data in d3 * Delete index.md
3.2 KiB
3.2 KiB
title
title |
---|
Work with Data in D3 |
Remember to use
Read-Search-Ask
if you get stuck. Try to pair program and write your own code
Problem Explanation:
We need to make h2
element as much as the number of values in dataset
with a text New Title
, using the data()
, enter()
functions.
Hint: 1
- You will need to select the
body
node, then select allh2
elements.
try to solve the problem now
Hint: 2
- You will need to D3 create and append an h2tag using
append()
for each item in the datasetarray usingdata()
andenter()
.
try to solve the problem now
Hint: 3
- The text in the
h2
should sayNew Title
bytext()
function.
try to solve the problem now
Spoiler Alert!
Solution ahead!
Basic Code Solution:
<body>
<script>
const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
// Add your code below this line
d3.select("body").selectAll("h2")
.data(dataset)
.enter()
.append("h2")
.text("New Title");
// Add your code above this line
</script>
</body>
NOTES FOR CONTRIBUTIONS:
DO NOT add solutions that are similar to any existing solutions. If you think it is similar but better, then try to merge (or replace) the existing similar solution.
- Add an explanation of your solution.
- Categorize the solution in one of the following categories <20> Basic, Intermediate and Advanced.
- Please add your username only if you have added any relevant main contents. (
DO NOT remove any existing usernames)
See
![]()
Wiki Challenge Solution Template
for reference.