Skip to content

Instantly share code, notes, and snippets.

@denisinla
Last active Aug 29, 2015
Embed
What would you like to do?
Messing with D3.
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<meta charset="utf-8">
<title>Messing with D3</title>
</head>
<body>
<h3>D3 Bar Charts</h3>
<div id="barchart"></div>
</body>
</html>
var data = [1,2,3,4,5,4,3,5,2,1];
var svg = d3.select("#barchart")
.append("svg")
.attr("width","240")
.attr("height","100");
svg.selectAll('rect')
.data(data)
.enter()
.append('rect')
.attr('x', function(d, i) { return i * 22; })
.attr('y', 100)
.attr('width', 20)
.attr('height', 0)
.transition()
.delay(function(d, i) { return i * 100; })
.duration(200)
.attr('y', function(d) { return 100 - d * 20; })
.attr('height', function(d) { return d * 20; });
body{
font: 16px Arial,Helvetica,sans-serif;
color: #111;
a,a:link,a:active{
color: #333;
text-decoration: none;
}
svg{
fill: #27ae60;
}
#barchart{
margin: 50px 0 0 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment