Instantly share code, notes, and snippets.

Embed
What would you like to do?
d3 consume api and build document
<!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>
@omaraboumrad

This comment has been minimized.

Copy link
Owner

omaraboumrad commented Feb 21, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment