Files
freeCodeCamp/guide/english/d3/data-visualization-with-d3-work-with-data-in-d3/index.md
M Rumman Hasan Khan ee77adbee9 Guide to the Data Visualization with D3 Work with Data in D3 (#36651)
* 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
2019-08-22 10:14:48 -07:00

3.2 KiB
Raw Blame History

title
title
Work with Data in D3

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

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.

:speech_balloon: Hint: 1

  • You will need to select the body node, then select all h2 elements.

try to solve the problem now

:speech_balloon: Hint: 2

  • You will need to D3 create and append an h2tag using append() for each item in the datasetarray using data() and enter().

try to solve the problem now

:speech_balloon: Hint: 3

  • The text in the h2 should say New Title by text() function.

try to solve the problem now

Spoiler Alert!

warning sign

Solution ahead!

:beginner: 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>

:clipboard: NOTES FOR CONTRIBUTIONS:

  • :warning: 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. :traffic_light:
  • Please add your username only if you have added any relevant main contents. (:warning: DO NOT remove any existing usernames)

See :point_right: Wiki Challenge Solution Template for reference.