How do I place the first row of entries in a csv file into a table heading using d3.csv?
Here's my csv data file:
Surname,Name,Phone,eMail
Stupich,Andrew,719-817-2323,Andy@foo.org
Miles,Wally,719-415-7177,Wally@foo.org
McLaren,Brenda,719-817-1096,Brenda@foo.org
Here's my html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3.csv Demo</title>
<style type="text/css">
body {
margin-left: 4%;
margin-right: 4%;
}
table {
border-collapse: collapse;
border: 2px #000 solid;
}
th {
border: 1px #F00 solid;
text-align: center;
font-weight: bold;
}
td {
border: 1px #00F solid;
text-align: center;
padding: 5px;
}
</style>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" charset="utf-8">
d3.text("DemoData.csv", function(datasetText) {
var parsedCSV = d3.csv.parseRows(datasetText);
var sampleHTML = d3.select("#viz6")
.append("table")
.selectAll("tr")
.data(parsedCSV)
.enter().append("tr")
.selectAll("td")
.data(function(d){return d;})
.enter().append("td")
.text(function(d){return d;})
});
</script>
</head>
<body>
<h1>D3.csv Demo</h1>
<div id="viz6"></div>
</body>
</html>
How and where do I place th
row? Does it have something to do with d3.text vs d3.csv?
Thanks for your help; please be patient, I'm completely new to d3.csv with js - not quite certain how any of it works - what documentation I can find is completely incomprehensible to a beginner. (I'm comfortable with HTML/CSS/PHP)