-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchart.html
95 lines (71 loc) · 2.34 KB
/
chart.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
layout: default
chart: true
title: Netafilter - Charts
description: Explore Candidate data using
---
<h1>Neta ji, how do you do?</h1>
<h2>Education vs declared assets</h2>
<svg id='chart1' style="height:400px;"></svg>
<h2>Criminal cases vs declared assets</h2>
<svg id='chart2' style="height:400px;"></svg>
<h2>Party vs criminal cases</h2>
<svg id='chart3' style="height:400px;"></svg>
<h2>Stae vs criminal cases</h2>
<svg id='chart4' style="height:400px;"></svg>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
window.chart = [];
//
// Chart 1: Scatter chart of candidate education vs assets
nv.addGraph(function() {
chart[1] = nv.models.scatterChart()
.showDistY(true)
.duration(100)
.x(function(d) {
return d['myneta Education Points'];
})
.y(function(d) {
return d['myneta Total Assets'];
})
.pointSize(function(d) {
return d['myneta Criminal Case'];
})
// .color(d3.scale.category20().range());
.color(d3.scale.category20().range())
.width(800);
// Chart formatting
chart[1].tooltip.contentGenerator(function(obj) {
console.log(obj);
return '<h3>' + obj.point['myneta Candidate'] + '</h3><br><h4>' + obj.point['PC_NAME2'] + ', ' + obj.point['ST_NAME'] + '</h4><p>' + obj.point['myneta Criminal Case'] + ' criminal cases</p>'
}).headerEnabled(true)
chart[1].xAxis.axisLabel('Education (years)').tickFormat(d3.format('d'))
chart[1].yAxis.axisLabel('Assets (Rs. crore)').tickFormat(d3.format('d'));
// Resize charts
nv.utils.windowResize(chart[1].update);
// Attach chart to the page
d3.select('#chart1')
.datum(mynetaData)
.call(chart[1]);
return chart;
});
var mynetaData;
d3.csv("data/myneta-loksabha.csv", function(data) {
// Data cleanup: parse strings to integers http://learnjsdata.com/read_data.html
data.forEach(function(d, i) {
d['myneta Education Points'] = +d['myneta Education Points']
d['myneta Total Assets'] = +d['myneta Total Assets'] / 10000000
d['myneta Criminal Case'] = +d['myneta Criminal Case']
});
// Group data by state
mynetaData = d3.nest()
.key(function(d) {
return d['ST_NAME'];
})
.sortKeys(d3.ascending)
.entries(data);
// DEBUG
window.data = mynetaData;
console.log(window.data);
});
</script>