Learn About SVG in D3

Learn About SVG in D3
0

#1

Tell us what’s happening:

Your code so far


<style>
  svg {
    background-color: pink;
    
  }
</style>
<body>
  <script>
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
    
    const w = 500;
    const h = 100;
    
    const svg = d3.select("body").append("svg")
                  // Add your code below this line
                  
                  .attr({width: "500",height: "100"})
                  
                  // Add your code above this line
  </script>
</body>

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/data-visualization/data-visualization-with-d3/learn-about-svg-in-d3
what is wrong with my code ?


#2

The .attr method doesn’t accept an object like in your code. It needs two arguments: the attribute that you want to change (as a string), and the value. You can only change one particular attribute per .attr() call, so you need to chain two of them together.

//...
.append('svg')
.attr('width', 500)
.attr('height', 100)

#3

Spoiler alert! @kevcomedia