Skip to content

Instantly share code, notes, and snippets.

@romsson
Last active January 4, 2016 15:18
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
rect {
fill:teal;
fill-opacity:.8;
}
</style>
</head>
<body>
<script type="text/javascript">
var margin = {top: 50, bottom: 10, left:300, right: 40};
var width = 900 - margin.left - margin.right;
var height = 900 - margin.top - margin.bottom;
var xScale = d3.scale.linear().range([0, width]);
var yScale = d3.scale.ordinal().rangeRoundBands([0, height], .8, 0);
var svg = d3.select("body").append("svg")
.attr("width", width+margin.left+margin.right)
.attr("height", height+margin.top+margin.bottom);
var g = svg.append("g")
.attr("transform", "translate("+margin.left+","+margin.top+")");
d3.tsv("unemp_states_us_nov_2013.tsv", function(data) {
var max = d3.max(data, function(d) { return d.Rate; } );
var min = 0;
xScale.domain([min, max]);
yScale.domain(data.map(function(d) { return d.State; }));
var groups = g.append("g")
.selectAll("text")
.data(data)
.enter()
.append("g");
var bars = groups
.append("rect")
.attr("width", function(d) { return xScale(d.Rate); })
.attr("height", 15 )
.attr("x", xScale(min))
.attr("y", function(d) { return yScale(d.State); })
});
</script>
</body>
</html>
Rank State Rate
1 NORTH DAKOTA 2.6
2 SOUTH DAKOTA 3.6
3 NEBRASKA 3.7
4 UTAH 4.3
5 HAWAII 4.4
5 IOWA 4.4
5 VERMONT 4.4
5 WYOMING 4.4
9 MINNESOTA 4.6
10 KANSAS 5.1
10 NEW HAMPSHIRE 5.1
12 MONTANA 5.2
13 OKLAHOMA 5.4
13 VIRGINIA 5.4
15 IDAHO 6.1
15 MISSOURI 6.1
15 TEXAS 6.1
15 WEST VIRGINIA 6.1
19 ALABAMA 6.2
20 LOUISIANA 6.3
20 WISCONSIN 6.3
22 FLORIDA 6.4
22 MAINE 6.4
22 MARYLAND 6.4
22 NEW MEXICO 6.4
26 ALASKA 6.5
26 COLORADO 6.5
26 DELAWARE 6.5
29 WASHINGTON 6.8
30 MASSACHUSETTS 7.1
30 SOUTH CAROLINA 7.1
32 INDIANA 7.3
32 OREGON 7.3
32 PENNSYLVANIA 7.3
35 NEW YORK 7.4
35 NORTH CAROLINA 7.4
35 OHIO 7.4
38 ARKANSAS 7.5
39 CONNECTICUT 7.6
40 GEORGIA 7.7
41 ARIZONA 7.8
41 NEW JERSEY 7.8
43 TENNESSEE 8.1
44 KENTUCKY 8.2
45 MISSISSIPPI 8.3
46 CALIFORNIA 8.5
47 DISTRICT OF COLUMBIA 8.6
48 ILLINOIS 8.7
49 MICHIGAN 8.8
50 NEVADA 9.0
50 RHODE ISLAND 9.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment