Clone of Mike Bostock's "Bar Chart II"
-
-
Save enactdev/d841cd11ac25081ca52f to your computer and use it in GitHub Desktop.
Website trackers on newssites
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> | |
<meta charset="utf-8"> | |
<style> | |
.chart rect { | |
fill: steelblue; | |
} | |
.chart text { | |
fill: white; | |
font: 10px sans-serif; | |
text-anchor: end; | |
} | |
</style> | |
<svg class="chart"></svg> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<script> | |
var width = 420, | |
barHeight = 20; | |
var x = d3.scale.linear() | |
.range([0, width]); | |
var chart = d3.select(".chart") | |
.attr("width", width); | |
d3.csv("web_trackers.csv", type, function(error, data) { | |
x.domain([0, d3.max(data, function(d) { return d.num_trackers; })]); | |
chart.attr("height", barHeight * data.length); | |
var bar = chart.selectAll("g") | |
.data(data) | |
.enter().append("g") | |
.attr("transform", function(d, i) { return "translate(0," + i * barHeight + ")"; }); | |
bar.append("rect") | |
.attr("width", function(d) { return x(d.num_trackers); }) | |
.attr("height", barHeight - 1); | |
bar.append("text") | |
.attr("x", function(d) { return x(d.num_trackers) - 3; }) | |
.attr("y", barHeight / 2) | |
.attr("dy", ".35em") | |
.text(function(d) { return d.website; }); | |
}); | |
function type(d) { | |
d.num_trackers = +d.num_trackers; // coerce to number | |
return d; | |
} | |
</script> |
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
alexa_rank | website | num_trackers | |
---|---|---|---|
19 | cnn.com | 26 | |
22 | espn.go.com | 14 | |
29 | nytimes.com | 44 | |
31 | huffingtonpost.com | 59 | |
37 | buzzfeed.com | 25 | |
44 | foxnews.com | 40 | |
50 | washingtonpost.com | 41 | |
66 | dailymail.co.uk | 76 | |
67 | cnet.com | 37 | |
68 | usatoday.com | 27 | |
72 | ijreview.com | 95 | |
73 | forbes.com | 45 | |
81 | businessinsider.com | 68 | |
89 | vice.com | 28 | |
92 | bleacherreport.com | 70 | |
97 | bbc.com | 37 | |
100 | nbcnews.com | 80 | |
103 | wsj.com | 28 | |
111 | theguardian.com | 36 | |
117 | people.com | 56 | |
123 | patch.com | 78 | |
124 | drudgereport.com | 112 | |
133 | gizmodo.com | 26 | |
137 | npr.org | 19 | |
140 | time.com | 40 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment