Skip to content

Instantly share code, notes, and snippets.

@jamesduncombe
Created April 8, 2014 16:58
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 jamesduncombe/10155963 to your computer and use it in GitHub Desktop.
Save jamesduncombe/10155963 to your computer and use it in GitHub Desktop.
CSV to HTML table
data = """
Make, Model
Jag, X-type
Merc, CL
"""
csv = d3.csv.parse(data)
columns = Object.keys(csv[0])
# Create the actual body of the table
table = d3.select('body').append('table')
thead = table.append('thead')
tbody = table.append('tbody')
# Draw out the header
thead.append('tr')
.selectAll('th')
.data(columns).enter()
.append('th')
.text (d) -> d
# Add the rows
rows = tbody.selectAll('tr')
.data(csv).enter()
.append('tr')
# Add the cells
cells = rows.selectAll('td')
.data((row) ->
columns.map((column) -> row[column])
).enter()
.append('td').text (d) -> d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment