Created
June 15, 2016 07:19
-
-
Save ozluy/7a38f2981b99fe4336945bf9103f5d08 to your computer and use it in GitHub Desktop.
D3 - simple data useage
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> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="shape"> | |
</div> | |
</body> | |
</html> |
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
var w =100; | |
var h = 100; | |
var padding = 2; | |
var dataSet = [5, 10, 15, 20, 25]; | |
var svg = d3.select("#shape") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
svg.selectAll("rect") | |
.data(dataSet) | |
.enter() | |
.append("rect") | |
.attr("x", function(d, i){ return i * (w / dataSet.length);}) | |
.attr("y", function(d){return h- (d * 4)}) | |
.attr("width", w / dataSet.length - padding) | |
.attr("height", function(d){ return d * 4;}) | |
.style("fill", "blue") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment