Learn About SVG in D3

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:


what is wrong with my code ?

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)
2 Likes

Spoiler alert! @kevcomedia

1 Like