Last active
January 20, 2016 21:07
-
-
Save dgkeyes/20fcaa11182bd12c0f4b to your computer and use it in GitHub Desktop.
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 lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Sorting Elements</title> | |
<script type="text/javascript" src="https://d3js.org/d3.v3.min.js"></script> | |
<style type="text/css"> | |
body { | |
background-color: #ddddff; | |
} | |
svg { | |
background-color: white; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", 900) | |
.attr("height", 500); | |
d3.csv("oregon-latino-pop.csv", function(data) { | |
data.sort(function(a, b) { | |
// return d3.descending(a.HISPANIC2010, b.HISPANIC2010); | |
return d3.descending(+a.HISPANIC2010, +b.HISPANIC2010); | |
//If your numeric values aren't sorting properly, | |
//try commenting out the line above, and instead using: | |
// | |
//return d3.descending(+a.lifeSatisfaction, +b.lifeSatisfaction); | |
// | |
//Data coming in from the CSV is saved as strings (text), | |
//so the + signs here force JavaScript to treat those | |
//strings instead as numeric values, thereby fixing the | |
//sort order (hopefully!). | |
}); | |
var rects = svg.selectAll("rect") | |
.data(data) | |
.enter() | |
.append("rect"); | |
rects.attr("x", 0) | |
.attr("y", function(d, i) { | |
return i * 10; | |
}) | |
.attr("width", function(d) { | |
return d.HISPANIC2010 * .01; | |
}) | |
.attr("height", 8) | |
.append("title") | |
.text(function(d) { | |
return d.COUNTY + "'s 2010 Hispanic population is " + d.HISPANIC2010; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
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
COUNTY | 1990 TOTAL POPULATION | 1990 NON-HISPANIC POPULATION | 1990 HISPANIC POPULATION | 2000 TOTAL POPULATION | 2000 NON-HISPANIC POPULATION | 2000 HISPANIC POPULATION | 2010 TOTAL POPULATION | 2010 NON-HISPANIC POPULATION | HISPANIC2010 | |
---|---|---|---|---|---|---|---|---|---|---|
Baker County | 15317 | 15041 | 276 | 16741 | 16349 | 392 | 16134 | 15606 | 528 | |
Benton County | 70811 | 69076 | 1735 | 78153 | 74508 | 3645 | 85579 | 80112 | 5467 | |
Clackamas County | 278850 | 271721 | 7129 | 338391 | 321647 | 16744 | 375992 | 346854 | 29138 | |
Clatsop County | 33301 | 32653 | 648 | 35630 | 34033 | 1597 | 37039 | 34201 | 2838 | |
Columbia County | 37557 | 36873 | 684 | 43560 | 42467 | 1093 | 49351 | 47364 | 1987 | |
Coos County | 60273 | 58920 | 1353 | 62779 | 60646 | 2133 | 63043 | 59652 | 3391 | |
Crook County | 14111 | 13723 | 388 | 19182 | 18100 | 1082 | 20978 | 19515 | 1463 | |
Curry County | 19327 | 18973 | 354 | 21137 | 20376 | 761 | 22364 | 21163 | 1201 | |
Deschutes County | 74958 | 73432 | 1526 | 115367 | 111063 | 4304 | 157733 | 146015 | 11718 | |
Douglas County | 94649 | 92424 | 2225 | 100399 | 97116 | 3283 | 107667 | 102612 | 5055 | |
Gilliam County | 1717 | 1687 | 30 | 1915 | 1880 | 35 | 1871 | 1783 | 88 | |
Grant County | 7853 | 7701 | 152 | 7935 | 7772 | 163 | 7445 | 7238 | 207 | |
Harney County | 7060 | 6839 | 221 | 7609 | 7293 | 316 | 7422 | 7128 | 294 | |
Hood River County | 16903 | 14151 | 2752 | 20411 | 15304 | 5107 | 22346 | 15757 | 6589 | |
Jackson County | 146389 | 140440 | 5949 | 181269 | 169143 | 12126 | 203206 | 181461 | 21745 | |
Jefferson County | 13676 | 12228 | 1448 | 19009 | 15637 | 3372 | 21720 | 17525 | 4195 | |
Josephine County | 62649 | 60900 | 1749 | 75726 | 72497 | 3229 | 82713 | 77462 | 5251 | |
Klamath County | 57702 | 54718 | 2984 | 63775 | 58814 | 4961 | 66380 | 59465 | 6915 | |
Lake County | 7186 | 6916 | 270 | 7422 | 7018 | 404 | 7895 | 7350 | 545 | |
Lane County | 282912 | 276060 | 6852 | 322959 | 308085 | 14874 | 351715 | 325548 | 26167 | |
Lincoln County | 38889 | 38291 | 598 | 44479 | 42360 | 2119 | 46034 | 42379 | 3655 | |
Linn County | 91227 | 89050 | 2177 | 103069 | 98555 | 4514 | 116672 | 107545 | 9127 | |
Malheur County | 26038 | 20883 | 5155 | 31615 | 23516 | 8099 | 31313 | 21446 | 9867 | |
Marion County | 228483 | 210258 | 18225 | 284834 | 236120 | 48714 | 315335 | 238741 | 76594 | |
Morrow County | 7625 | 6800 | 825 | 10995 | 8309 | 2686 | 11173 | 7676 | 3497 | |
Multnomah County | 583887 | 565497 | 18390 | 660486 | 610879 | 49607 | 735334 | 655196 | 80138 | |
Polk County | 49541 | 46739 | 2802 | 62380 | 56900 | 5480 | 75403 | 66315 | 9088 | |
Sherman County | 1918 | 1890 | 28 | 1934 | 1840 | 94 | 1765 | 1667 | 98 | |
Tillamook County | 21570 | 21196 | 374 | 24262 | 23018 | 1244 | 25250 | 22966 | 2284 | |
Umatilla County | 59249 | 53942 | 5307 | 70548 | 59182 | 11366 | 75889 | 57782 | 18107 | |
Union County | 23598 | 23217 | 381 | 24530 | 23930 | 600 | 25748 | 24746 | 1002 | |
Wallowa County | 6911 | 6798 | 113 | 7226 | 7101 | 125 | 7008 | 6852 | 156 | |
Wasco County | 21683 | 20618 | 1065 | 23791 | 21577 | 2214 | 25213 | 21470 | 3743 | |
Washington County | 311554 | 297153 | 14401 | 445342 | 395607 | 49735 | 529710 | 446440 | 83270 | |
Wheeler County | 1396 | 1384 | 12 | 1547 | 1468 | 79 | 1441 | 1379 | 62 | |
Yamhill County | 65551 | 61422 | 4129 | 84992 | 75975 | 9017 | 99193 | 84601 | 14592 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment