Skip to content

Instantly share code, notes, and snippets.

@phtseng
Created April 13, 2015 03:49
Show Gist options
  • Save phtseng/a36b8e878371881bd902 to your computer and use it in GitHub Desktop.
Save phtseng/a36b8e878371881bd902 to your computer and use it in GitHub Desktop.
Module 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Loading CSV Prisons Data with D3</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<style type="text/css">
body {
background-color: #ddddff;
}
svg {
background-color: white;
}
</style>
</head>
<body>
<svg width="800" height="500">
<line x1="50" y1="10" x2="50" y2="50" stroke="black" stroke-width="3" />
<line x1="50" y1="110" x2="50" y2="100" stroke="blue" stroke-width="3" />
<line x1="50" y1="210" x2="50" y2="150" stroke="black" stroke-width="3" />
<circle cx="150" cy="110" r="50" fill="violet" />
<circle cx="250" cy="110" r="50" fill="blue" />
<circle cx="350" cy="110" r="50" fill="green" />
<line x1="450" y1="10" x2="50" y2="50" stroke="black" stroke-width="3" />
<line x1="450" y1="110" x2="50" y2="100" stroke="blue" stroke-width="3" />
<line x1="450" y1="210" x2="50" y2="150" stroke="black" stroke-width="3" />
</svg>
<script type="text/javascript">
//Load in contents of CSV file
d3.csv("priceofprisonsperinmate.csv", function(data) {
//Now CSV contents have been transformed into
//an array of JSON objects.
//Log 'data' to the console, for verification.
console.log(data);
});
</script>
</body>
</html>
State AverageDailyInmatePopulation TaxpayerCostofPrisons AvgAnnualcpInmate
Alabama 26,758 $462,507 $17,285
Arizona 40,458 $1,003,553 $24,805
Arkansas 13,369 $326,081 $24,391
California 167,276 $7,932,388 $47,421
Colorado 19,958 $606,208 $30,374
Connecticut 18,492 $929,438 $50,262
Delaware 6,528 $215,210 $32,967
Florida 101,324 $2,082,531 $20,553
Georgia 53,704 $1,129,858 $21,039
Idaho 7,402 $144,669 $19,545
Illinois 45,551 $1,743,153 $38,268
Indiana 38,417 $569,451 $14,823
Iowa 8,384 $276,039 $32,925
Kansas 8,689 $158,198 $18,207
Kentucky 21,347 $311,727 $14,603
Louisiana 39,938 $698,363 $17,486
Maine 2,167 $100,558 $46,404
Maryland 21,786 $836,223 $38,383
Michigan 45,096 $1,267,954 $28,117
Minnesota 9,557 $395,319 $41,364
Missouri 30,447 $680,487 $22,350
Montana 2,513 $75,959 $30,227
Nebraska 4,542 $163,284 $35,950
Nevada 13,696 $282,903 $20,656
New Hampshire 2,389 $81,417 $34,080
New Jersey 25,822 $1,416,727 $54,865
New York 59,237 $3,558,711 $60,076
North Carolina 40,203 $1,204,667 $29,965
North Dakota 1,479 $58,065 $39,271
Ohio 50,960 $1,315,477 $25,814
Oklahoma 24,549 $453,356 $18,467
Pennsylvania 48,543 $2,055,269 $42,339
Rhode Island 3,502 $172,063 $49,133
Texas 154,576 $3,306,358 $21,390
Utah 6,338 $186,013 $29,349
Vermont 2,248 $111,280 $49,502
Virginia 29,792 $748,642 $25,129
Washington 17,050 $799,590 $46,897
West Virginia 6,385 $169,190 $26,498
Wisconsin 23,015 $874,421 $37,994
Total (40 states) 1,243,487 $38,903,304 $31,286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment