-
Notifications
You must be signed in to change notification settings - Fork 1
/
expense.html
220 lines (204 loc) · 6.66 KB
/
expense.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<head>
<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>
<script src="js/colorbrewer.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/dc.css" rel="stylesheet">
<link href="css/style (2).css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link href="css/font-awesome.min.css" rel="stylesheet">
<title>Expense Cut</title>
</head>
<nav class="menu" id="theMenu">
<div class="menu-wrap">
<h1 class="logo"><a href="index.html#home">HOME</a></h1>
<i class="fa fa-arrow-right menu-close"></i>
<a href="index.html">Home</a>
<a href="dc.html">GSDP of State</a>
<a href="gvis.html">Google Visualisation</a>
<a href="stateinvest.html">Statewise Investment Proposal</a>
<a href="sectorinvest.html">Sectorwise Investment Proposal</a>
<a href="homeasset.html">2013 Census Home Asset</a>
<a href="districtcrime.html">Districtwise IPC crimes in 2013</a>
<a href="statecrop.html">Statewise Crop Production</a>
<a href="kaggletitanic.html">Kaggle Titanic Data</a>
<a href="#contact">Contact</a>
<a href="#"><i class="fa fa-facebook"></i></a>
<a href="#"><i class="fa fa-twitter"></i></a>
<a href="#"><i class="fa fa-dribbble"></i></a>
<a href="#"><i class="fa fa-envelope"></i></a>
</div>
<!-- Menu button -->
<div id="menuToggle"><i class="fa fa-bars"></i></div>
</nav>
<div class="container-fluid">
<div class="row-fluid">
<div class="col-md-12" id="expbar2"><h3>Description</h3></div>
</div>
<div class="row-fluid">
<div class="col-md-8" id="bar"><h3>Expense</h3></div>
<div class="col-md-4" id="ring"><h3>Category Cut</h3></div>
<div classs="row-fluid">
<table class="table table-hover dc-data-table list table-striped table-bordered"></table>
</div>
</div>
<div class="clearfix"></div>
<script>
var parseDate = d3.time.format("%d-%m-%Y").parse;
//var month = d3.time.format("%b");
var data=d3.csv("data/expense.csv", function(error, data){
data.forEach(function(d) {
d.date=parseDate(d.Date);
d.month=d3.time.month(d.date);
d.amt=d3.round(d.Amount);
});
var ndx=crossfilter(data);
var all = ndx.groupAll();
function remove_empty_bins(source_group) {
return {
all:function () {
return source_group.all().filter(function(d) {
return d.value != 0;
});
}
};
}
//Description
var descDim = ndx.dimension(function(d){return d.Subcategory;});
var desc_tot = descDim.group().reduceSum(function(d) { return d.amt; });
var filtered_group = remove_empty_bins(desc_tot)
var statebar = dc.barChart("#expbar2");
statebar
.margins({ top: -15, left: 40, right: 0, bottom: 10})
.width(1200).height(280)
.dimension(descDim)
.transitionDuration(500)
.group(filtered_group)
.x(d3.scale.ordinal())
.xUnits(dc.units.ordinal)
.ordering(function(d){return -d.value;})
.elasticY(true)
.elasticX(true)
.turnOnControls()
.colors('purple')
.renderlet(function (chart) {
chart.selectAll("g.x text")
.attr('dx', '40')
.attr('dy', '-8')
.attr('transform', "rotate(-90)");
});
//Timewise Expense
var timeDim = ndx.dimension(function(d){return d.month});
var amt = timeDim.group().reduceSum(dc.pluck('Amount'));
var invbarchart = dc.barChart("#bar");
var minDate = timeDim.bottom(1)[0]["Date"];
var maxDate = timeDim.top(1)[0]["Date"];
//invbarchart.xUnits(function(){return 1;}); //manually setting bar width
invbarchart
.width(650).height(270)
.dimension(timeDim)
.group(amt)
.elasticY(true)
.elasticX(true)
.xAxisPadding(100)
.gap(4)
.centerBar(true)
.xUnits(d3.time.months)
.x(d3.time.scale())
.margins({top: 10, left: 40, right: 15, bottom: 20})
.title(function(d) { return "Value: " + d.amt; })
.renderTitle(true);
//.renderlet(function (chart) {
// chart.selectAll("g.x text")
// .attr('dx', '-30')
// .attr('dy', '-1')
// .attr('transform', "rotate(-50)");
// })
;
invbarchart.xAxis().tickFormat(d3.time.format("%b-%y"));
invbarchart.xAxis().ticks(d3.time.months);
//invbarchart.xUnits(function(){return 15;})
//Category Percent
var gdpbarchart = dc.pieChart("#ring");
var sectorDim = ndx.dimension(function(d){return d.Category;});
var nos = sectorDim.group().reduceSum(dc.pluck('Amount'));
gdpbarchart
.width(250).height(270)
.dimension(sectorDim)
.group(nos)
.innerRadius(30)
.legend(dc.legend().x(260).y(50).gap(15))
.label(function(d) {
return d3.round((d.value / d3.sum(nos.all(), function(d){ return d.value;}))*100)+"%";})
.renderLabel(true)
.turnOnControls();
//var dtDim = ndx.dimension(function(d){return d.Date});
var table = dc.dataTable(".dc-data-table");
table
.dimension(timeDim)
.group(function(d) {return d.Date;})
.size(15)
.columns([
function(d) { return d.Date; },
function(d) { return d.Description; },
function(d) { return +d.amt; },
function(d) { return d.Category; }
])
.sortBy(function(d) {
return +d.Amount;
})
.order(d3.descending)
.showGroups(false)
.on('renderlet', function (table) {
table.selectAll('.dc-table-group').classed('info', true);
});
//Amount Filter
/*var amtbarchart = dc.barChart("#new");
var binwidth = 0.2;
var amtDim = ndx.dimension(function(d){return d.Amount;});
var amta = amtDim.group().reduceCount();
amtbarchart
.width(350).height(270)
.dimension(amtDim)
.group(amta)
//.elasticX(true)
.x(d3.scale.linear().domain([0, 4000]))
.margins({top: 10, left: 2, right: 10, bottom: 50});
*/
/*var dtDim = ndx.dimension(function(d){return d.date});
var amta = dtDim.group().reduceSum(dc.pluck('Amount'));
var filt_amta = remove_empty_bins(amta)
var dtbarchart = dc.barChart("#new");
dtbarchart
.width(350).height(270)
.dimension(dtDim)
.group(filt_amta)
.elasticY(true)
.elasticX(true)
.xAxisPadding(10)
.gap(4)
.centerBar(true)
.xUnits(d3.time.day)
.x(d3.time.scale())
.margins({top: 10, left: 40, right: 5, bottom: 60})
.renderlet(function (chart) {
chart.selectAll("g.x text")
.attr('dx', '-20')
.attr('dy', '-1')
.attr('transform', "rotate(-90)");
})
;
dtbarchart.xAxis().tickFormat(d3.time.format("%d-%b"));
dtbarchart.xAxis().ticks(20);
*/
dc.renderAll();
});
</script>
<script src="js/main.js"></script>