Skip to content

Instantly share code, notes, and snippets.

@omaraboumrad
Created February 21, 2014 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omaraboumrad/9133318 to your computer and use it in GitHub Desktop.
Save omaraboumrad/9133318 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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