how to read data from a CSV and show it in the page.
Created
March 29, 2014 15:41
-
-
Save danharr/9856775 to your computer and use it in GitHub Desktop.
show data from a CSV
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
name | age | |
---|---|---|
alan | 10 | |
bob | 20 | |
colin | 30 | |
dave | 40 | |
edward | 50 |
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> | |
<meta charset="utf-8"> | |
<title>show data from CSV</title> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
</head> | |
<script type="text/javascript"> | |
var dataset; //Declare global var | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", 200) | |
.attr("height", 500); | |
d3.csv("data.csv", function(data) { | |
//Hand CSV data off to global variable so it's accessible later. | |
dataset = data; | |
//Call some other functions that | |
//generate your visualization, e.g.: | |
showdata(); | |
}); | |
function showdata() { | |
d3.select("body").selectAll("p") | |
.data(dataset) | |
.enter() | |
.append("p") | |
.text(function(d) {return d.name +", "+d.age;}); | |
}; | |
</script> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I copy the code to my local and run the index.html. It displays a blank page