Built with blockbuilder.org
Last active
February 21, 2018 02:33
-
-
Save tangert/4cba1ffea317b4fbc876bc7dbb50278f to your computer and use it in GitHub Desktop.
Data Binding learning
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; } | |
.bar-container { | |
display: flex; | |
flex-direction: horizontal; | |
} | |
.bar { | |
display: inline-block; | |
width: 50px; | |
margin: 0px 20px 0px 20px; | |
height: 50px; | |
background-color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<script> | |
// Feel free to change or delete any of the code you see in this editor! | |
var testData = [ 25, 7, 5, 26, 11, 8, 25, 14, 23]; | |
//Playign with text and styles | |
d3.select("body") | |
.data(testData) | |
.enter() | |
.append("p") | |
.text(function(d){ | |
return "Hello! " + d; | |
}) | |
.style("color", function(d) { | |
if(d>3){ | |
return "red"; | |
} else { | |
return "blue" | |
} | |
}) | |
.style("font-size",function(d){ | |
return d + "px" | |
}); | |
var barContainer = d3.select("body") | |
.append("div") | |
.attr("class","bar-container"); | |
// Basic bars | |
barContainer | |
.data(testData).enter() | |
.append("div") | |
.attr("class","bar") | |
.style("height", function(d){ | |
return d*10 + "px"; | |
}) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment