Built with blockbuilder.org
Last active
January 10, 2018 20:20
-
-
Save mukhtyar/1e6652ca51b77c78e4567874137ebc01 to your computer and use it in GitHub Desktop.
D3 - Data Binding 1
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
#chart { | |
margin: 3em; | |
} | |
.bar { | |
background-color: blue; | |
height: 20px; | |
margin-top: 2px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="chart"> | |
<div></div> | |
<div></div> | |
<div></div> | |
<div></div> | |
<div></div> | |
</div> | |
<script> | |
var data = [200, 60, 100, 80, 10]; | |
// Pair each number in the array with an empty div | |
// Set color, height, and spacing via CSS | |
d3.select('#chart') | |
.selectAll('div') | |
.data(data) | |
.attr('class', 'bar') | |
.style('width', function(d) { | |
return d + 'px'; | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment