-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdistrictgdp.html
68 lines (60 loc) · 2.37 KB
/
districtgdp.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
<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="js/d3.v3.min.js"></script>
<script src="js/crossfilter.min.js"></script>
<script src="js/dc.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/dc.css" rel="stylesheet">
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="col-md-6" id="choro"></div>
<div class="col-md-6" id="bar"></div>
</div>
<script>
var parseDate = d3.time.format("%Y").parse;
d3.csv("data/districtgdp1.csv", function(csv) {
csv.forEach(function(d) {
d.year=parseDate(d.year);
d.GDP=d3.round(d.GDP);
});
var data = crossfilter(csv);
var district = data.dimension(function(d){return d.District;});
var distsum = district.group().reduceSum(function(d) {return d.GDP;});
var time = data.dimension(function(d){return d.year;});
var timesum = time.group().reduceSum(function(d) {return d.GDP;});
var minDate = time.bottom(1)[0].year;
var maxDate = time.top(1)[0].year;
var choro = dc.geoChoroplethChart('#choro');
var bar = dc.barChart('#bar');
var proj = d3.geo.mercator().scale(900).center([95,25]);
d3.json("dist-geo.json", function(dist){
choro.width(700)
.height(600)
.dimension(district)
.group(distsum)
.projection(proj)
.colors(d3.scale.quantize().range(["#E2F2FF", "#C4E4FF", "#9ED2FF", "#6BBAFF", "#36A2FF", "#1E96FF", "#0089FF", "#0061B5"]))
.colorDomain([300, 150000])
.colorCalculator(function (d) { return d ? choro.colors()(d) : '#ccc'; })
.overlayGeoJson(dist.features, "district", function (d) {
return d.properties.DISTRICT;
});
bar.xUnits(function(){return 18;}); //manually setting bar width
bar
.margins({top: 25, left: 60, right: 10, bottom: 20})
.width(500).height(350)
.dimension(time)
.group(timesum)
.elasticY(true)
.x(d3.time.scale().domain([minDate,maxDate]));
dc.renderAll();
});
});
</script>
</body>
</html>