-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenderGeneratedFrequency.html
69 lines (55 loc) · 2.01 KB
/
genderGeneratedFrequency.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.bar {
fill: steelblue;
}
.x.axis path {
display: none;
}
</style>
<body>
<script src="http://d3js.org/d3.v2.min.js?2.10.0"></script>
<script>
var margin = {top: 20, right: 30, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.rangeRoundBands([0, width], .1, .2);
var y = d3.scale.linear()
.range([height, 0]);
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv("/Users/nningego/Documents/workspace/BigData/d3js/UIDAI-ENR-GEN-AGE-20130326.csv", function(people) {
people.forEach(function(d) { d.generated = +d.generated; });
x.domain(people.map(function(d) { return d.gender; }));
y.domain([0, d3.max(people, function(d) { return d.generated; })]);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(d3.svg.axis().scale(x).orient("bottom"));
svg.append("g")
.attr("class", "y axis")
.call(d3.svg.axis().scale(y).orient("left"));
svg.selectAll(".bar")
.data(people)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) { return x(d.gender); })
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.generated); })
.attr("height", function(d) { return height - y(d.generated); });
});
</script>