Last active
December 10, 2015 20:28
-
-
Save int3h/4488051 to your computer and use it in GitHub Desktop.
D3.js Bar Chart Demo
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
<html> | |
<head> | |
<title>D3 Bar Chart Demo</title> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<style type="text/css"> | |
.chart {margin: 2em auto auto auto;} | |
div.bar { | |
display: inline-block; | |
width: 20px; | |
margin-right: 2px; | |
background-color: teal; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="chart"> | |
</div> | |
<script type="text/javascript"> | |
var dataset = [ 5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ]; | |
d3.select(".chart").selectAll("div") | |
.data(dataset) | |
.enter() | |
.append("div") | |
.attr("class", "bar") | |
.style("height", function(d) { | |
var barHeight = d * 5; | |
return barHeight + "px"; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment