Created
February 21, 2014 12:19
-
-
Save omaraboumrad/9133318 to your computer and use it in GitHub Desktop.
d3 consume api and build document
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> | |
<title>Reddit JSON</title> | |
<style> | |
body{ background-color: #C6C6C6; } | |
#content div { | |
border: 1px solid #000000; | |
margin: 5px; | |
padding: 5px; | |
} | |
span { margin: 5px; } | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script type="text/javascript"> | |
window.onload = function(){ | |
d3.json('http://www.reddit.com/r/hacketyfriends.json', function(err, data ){ | |
var content = d3.select("#content") | |
var topics = content.selectAll("div") | |
.data(data.data.children) | |
.enter() | |
.append("div") | |
.each(function(d){ | |
var self = d3.select(this); | |
var link = self.append("a") | |
.attr("href", d.data.url) | |
.text(d.data.title) | |
var author = self.append("span") | |
.text("by " + d.data.author); | |
if(d.data.selftext){ | |
var text = self.append("p") | |
.text(d.data.selftext); | |
} | |
}); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>Topics</h1> | |
<div id="content"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://bl.ocks.org/9133318