-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistics.js
95 lines (84 loc) · 2.74 KB
/
statistics.js
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
'use strict';
window.onload = () => {
let savingsBalanceStats = localStorage.getItem('totalSavings');
if (!transactions.length) {
const data = {
labels: [
'Expenses',
'Income',
'Savings',
],
datasets: [{
data: [1, 1, 1],
backgroundColor: [
'#E56372',
'#6488E5',
'#F9BE7D',
],
hoverOffset: 4
}]
};
const config = {
type: 'doughnut',
data: data,
};
const myChart = new Chart(
document.getElementById('myChart'),
config
);
} else {
const data = {
labels: [
'Expenses',
'Income',
'Savings',
],
datasets: [{
data: [parseInt(expenseBalance), parseInt(incomeBalance), parseInt(savingsBalanceStats)],
backgroundColor: [
'#E56372',
'#6488E5',
'#F9BE7D',
],
hoverOffset: 4
}]
};
const config = {
type: 'doughnut',
data: data,
};
const myChart = new Chart(
document.getElementById('myChart'),
config
);
}
//Filter transactions for card stats amount and display amount
const foodCardAmount = document.querySelector('.food-card-amount');
const shoppingCardAmount = document.querySelector('.shopping-card-amount');
const transportationCardAmount = document.querySelector('.transportation-card-amount');
const householdCardAmount = document.querySelector('.household-card-amount');
const savingsCardAmount = document.querySelector('.savings-card-amount');
let foodAmount = 0;
let shoppingAmount = 0;
let transportationAmount = 0;
let householdAmount = 0;
for (let i = 0; i <= transactions.length - 1; i++) {
if (transactions[i].category === 'Food') {
foodAmount += transactions[i].amount;
foodCardAmount.innerHTML = `- $ ${JSON.stringify(foodAmount).replace('-', '')}`;
}
if (transactions[i].category === 'Shopping') {
shoppingAmount += transactions[i].amount;
shoppingCardAmount.innerHTML = `- $ ${JSON.stringify(shoppingAmount).replace('-', '')}`;
}
if (transactions[i].category === 'Transportation' || transactions[i].category === 'Gas') {
transportationAmount += transactions[i].amount;
transportationCardAmount.innerHTML = `- $ ${JSON.stringify(transportationAmount).replace('-', '')}`;
}
if (transactions[i].category === 'Home' || transactions[i].category === 'Bills') {
householdAmount += transactions[i].amount;
householdCardAmount.innerHTML = `- $ ${JSON.stringify(householdAmount).replace('-', '')}`;
}
savingsCardAmount.innerHTML = `+ $ ${savingsBalanceStats}`;
}
}