Skip to content

Instantly share code, notes, and snippets.

@alexbbrown
Created December 31, 2012 22:19
Show Gist options
  • Save alexbbrown/4423290 to your computer and use it in GitHub Desktop.
Save alexbbrown/4423290 to your computer and use it in GitHub Desktop.
Simple table from nested data
{"description":"Simple table from nested data","endpoint":"","display":"html","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":false,"vim":true,"emacs":false,"fontSize":12},"USArrests.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"tab":"edit","display_percent":0.7,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"hidepanel":false}
var div = d3.select("#display");
ArrestsL = tributary.USArrests;
ArrestsW = d3.nest()
.key(function(x){return x.State})
.entries(ArrestsL)
var table = div.selectAll("table").data([ArrestsW])
table.enter().append("table")
.each(function(s){
var n=d3.select(this)
n.append("thead")
n.append("tbody")
})
head=table
.select("thead")
.selectAll("tr")
.data([ArrestsW[0]])
head.enter()
.append("tr")
.append("th").attr("class","key")
head.exit().remove()
head.select("tr th.key")
.text(function(d){return "State"})
cols=head
.selectAll("th.crime")
.data(function(d){return d.values})
cols.enter()
.append("th").attr("class","crime")
cols.exit().remove()
cols
.text(function(d){return d.Crime})
states=table
.select("tbody")
.selectAll("tr")
.data(ArrestsW)
states.enter()
.append("tr")
.append("td").attr("class","key")
states.exit().remove()
states.select("tr td.key")
.text(function(d){return d.key})
crimes=states
.selectAll("td.crime")
.data(function(d){return d.values})
crimes.enter()
.append("td").attr("class","crime")
crimes.exit().remove()
crimes
.text(function(d){return d.Count})
State Crime Count
Alabama Murder 13.2
Alaska Murder 10
Arizona Murder 8.1
Arkansas Murder 8.8
California Murder 9
Colorado Murder 7.9
Connecticut Murder 3.3
Delaware Murder 5.9
Florida Murder 15.4
Georgia Murder 17.4
Hawaii Murder 5.3
Idaho Murder 2.6
Illinois Murder 10.4
Indiana Murder 7.2
Iowa Murder 2.2
Kansas Murder 6
Kentucky Murder 9.7
Louisiana Murder 15.4
Maine Murder 2.1
Maryland Murder 11.3
Massachusetts Murder 4.4
Michigan Murder 12.1
Minnesota Murder 2.7
Mississippi Murder 16.1
Missouri Murder 9
Montana Murder 6
Nebraska Murder 4.3
Nevada Murder 12.2
New Hampshire Murder 2.1
New Jersey Murder 7.4
New Mexico Murder 11.4
New York Murder 11.1
North Carolina Murder 13
North Dakota Murder 0.8
Ohio Murder 7.3
Oklahoma Murder 6.6
Oregon Murder 4.9
Pennsylvania Murder 6.3
Rhode Island Murder 3.4
South Carolina Murder 14.4
South Dakota Murder 3.8
Tennessee Murder 13.2
Texas Murder 12.7
Utah Murder 3.2
Vermont Murder 2.2
Virginia Murder 8.5
Washington Murder 4
West Virginia Murder 5.7
Wisconsin Murder 2.6
Wyoming Murder 6.8
Alabama Assault 236
Alaska Assault 263
Arizona Assault 294
Arkansas Assault 190
California Assault 276
Colorado Assault 204
Connecticut Assault 110
Delaware Assault 238
Florida Assault 335
Georgia Assault 211
Hawaii Assault 46
Idaho Assault 120
Illinois Assault 249
Indiana Assault 113
Iowa Assault 56
Kansas Assault 115
Kentucky Assault 109
Louisiana Assault 249
Maine Assault 83
Maryland Assault 300
Massachusetts Assault 149
Michigan Assault 255
Minnesota Assault 72
Mississippi Assault 259
Missouri Assault 178
Montana Assault 109
Nebraska Assault 102
Nevada Assault 252
New Hampshire Assault 57
New Jersey Assault 159
New Mexico Assault 285
New York Assault 254
North Carolina Assault 337
North Dakota Assault 45
Ohio Assault 120
Oklahoma Assault 151
Oregon Assault 159
Pennsylvania Assault 106
Rhode Island Assault 174
South Carolina Assault 279
South Dakota Assault 86
Tennessee Assault 188
Texas Assault 201
Utah Assault 120
Vermont Assault 48
Virginia Assault 156
Washington Assault 145
West Virginia Assault 81
Wisconsin Assault 53
Wyoming Assault 161
Alabama UrbanPop 58
Alaska UrbanPop 48
Arizona UrbanPop 80
Arkansas UrbanPop 50
California UrbanPop 91
Colorado UrbanPop 78
Connecticut UrbanPop 77
Delaware UrbanPop 72
Florida UrbanPop 80
Georgia UrbanPop 60
Hawaii UrbanPop 83
Idaho UrbanPop 54
Illinois UrbanPop 83
Indiana UrbanPop 65
Iowa UrbanPop 57
Kansas UrbanPop 66
Kentucky UrbanPop 52
Louisiana UrbanPop 66
Maine UrbanPop 51
Maryland UrbanPop 67
Massachusetts UrbanPop 85
Michigan UrbanPop 74
Minnesota UrbanPop 66
Mississippi UrbanPop 44
Missouri UrbanPop 70
Montana UrbanPop 53
Nebraska UrbanPop 62
Nevada UrbanPop 81
New Hampshire UrbanPop 56
New Jersey UrbanPop 89
New Mexico UrbanPop 70
New York UrbanPop 86
North Carolina UrbanPop 45
North Dakota UrbanPop 44
Ohio UrbanPop 75
Oklahoma UrbanPop 68
Oregon UrbanPop 67
Pennsylvania UrbanPop 72
Rhode Island UrbanPop 87
South Carolina UrbanPop 48
South Dakota UrbanPop 45
Tennessee UrbanPop 59
Texas UrbanPop 80
Utah UrbanPop 80
Vermont UrbanPop 32
Virginia UrbanPop 63
Washington UrbanPop 73
West Virginia UrbanPop 39
Wisconsin UrbanPop 66
Wyoming UrbanPop 60
Alabama Rape 21.2
Alaska Rape 44.5
Arizona Rape 31
Arkansas Rape 19.5
California Rape 40.6
Colorado Rape 38.7
Connecticut Rape 11.1
Delaware Rape 15.8
Florida Rape 31.9
Georgia Rape 25.8
Hawaii Rape 20.2
Idaho Rape 14.2
Illinois Rape 24
Indiana Rape 21
Iowa Rape 11.3
Kansas Rape 18
Kentucky Rape 16.3
Louisiana Rape 22.2
Maine Rape 7.8
Maryland Rape 27.8
Massachusetts Rape 16.3
Michigan Rape 35.1
Minnesota Rape 14.9
Mississippi Rape 17.1
Missouri Rape 28.2
Montana Rape 16.4
Nebraska Rape 16.5
Nevada Rape 46
New Hampshire Rape 9.5
New Jersey Rape 18.8
New Mexico Rape 32.1
New York Rape 26.1
North Carolina Rape 16.1
North Dakota Rape 7.3
Ohio Rape 21.4
Oklahoma Rape 20
Oregon Rape 29.3
Pennsylvania Rape 14.9
Rhode Island Rape 8.3
South Carolina Rape 22.5
South Dakota Rape 12.8
Tennessee Rape 26.9
Texas Rape 25.5
Utah Rape 22.9
Vermont Rape 11.2
Virginia Rape 20.7
Washington Rape 26.2
West Virginia Rape 9.3
Wisconsin Rape 10.8
Wyoming Rape 15.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment