Built with blockbuilder.org
Created
February 28, 2018 16:52
-
-
Save vpascual/ecc2ffa6de05b968016a1406f4adf523 to your computer and use it in GitHub Desktop.
Barchart with SVG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>D3 Page Template</title> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
// D3 code | |
const data = [18, 20, 25, 34, 100] | |
barHeight = 15; | |
var scale = d3.scaleLinear() | |
.domain([0, d3.max(data)]) | |
.range([0, 400]); | |
var svg = d3.select("body").append("svg"); | |
svg.selectAll("rect") | |
.data(data) | |
.enter() | |
.append("rect") | |
.attr("x", 0) | |
.attr("y", (d, i) => { return barHeight * i; }) | |
.attr("width", (d) => { return scale(d); }) | |
.attr("height", barHeight) | |
.style("fill", "steelblue"); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment