Work with Data in D3 explaination

Work with Data in D3 explaination
0

#1

i passed this test but i need some explanation on this,i thought i have to pass the values of the array into h2 but it basically creates h1 elements = dataset.length. What is the point of this?(Hope i am not being impatient)

Your code so far


<body>
  <script>
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
    
    // Add your code below this line
    d3.select('body').selectAll('h1')
    .data(dataset)
    .enter()
    .append('h2')
    .text('New Title') ;   
    
    // Add your code above this line
  </script>
</body>

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/data-visualization/data-visualization-with-d3/work-with-data-in-d3


#2

I think I don’t understand your question.

You should select() the h2 instead of h1 because it’s the element being cloned as many times as the number of elements in the dataset that you’re passing to the data() method.


#3

i meant that how are the values of the array being passed into the variable d


#4

I think you’re crossing threads here lol

The conversation about the variable d is in another thread :smiley: