Built with blockbuilder.org
forked from molliemarie's block: BarChart2_D3_Complete
forked from molliemarie's block: BarChart2_D3_Starter
| license: mit |
Built with blockbuilder.org
forked from molliemarie's block: BarChart2_D3_Complete
forked from molliemarie's block: BarChart2_D3_Starter
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Second Bar Chart Using D3!</title> | |
| <style> | |
| /* Set `rect` elements to have a "fill" of "purple" or whatever color you choose */ | |
| rect { | |
| fill: purple; | |
| } | |
| svg { | |
| border: 1px solid #f0f; | |
| } | |
| </style> | |
| <!--- Load the d3 library --> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| </head> | |
| <body> | |
| </body> | |
| <script type="text/javascript"> | |
| // 1) Select your `body` and append a `div` element in which you'll render your content. To do this, you'll use the `d3.select()` method, and then the `.append()` method to append your element to your selection. | |
| var div = d3.select("body").append("div") | |
| div.append("p").text("My Bar Chart") | |
| // 2) Append a new `p` element to the `div` you just created, and use the `.text()` method to set the text to "My Bar Chart" | |
| var svg = div.append("svg") | |
| .attr("width", 300) | |
| .attr("height", 400) | |
| var r1 = svg.append("rect") | |
| .attr("x", 0) | |
| .attr("y", 10) | |
| .attr("width", 100) | |
| .attr("height", 20) | |
| var r2 = svg.append("rect") | |
| .attr("x", 0) | |
| .attr("y", 40) | |
| .attr("width", 200) | |
| .attr("height", 20) | |
| var r2 = svg.append("rect") | |
| .attr("x", 0) | |
| .attr("y", 70) | |
| .attr("width", 300) | |
| .attr("height", 20) | |
| // 3) Append a container `svg` to your `div` element in which you'll place your rectangles | |
| // 4) Append 3 `rect` elements inside of your `<svg>` (one at a time), setting the properties for each one. | |
| </script> | |
| </html> |