-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
133 lines (128 loc) · 6 KB
/
script.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
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
// on window load
window.onload = function () {
function getIncomeValues() {
// get input value for januaryincome
var januaryincome = document.getElementById("januaryIncome").value;
// get input value for februaryincome
var februaryincome = document.getElementById("februaryIncome").value;
// get input value for marchincome
var marchincome = document.getElementById("marchIncome").value;
// get input value for aprilincome
var aprilincome = document.getElementById("aprilIncome").value;
// get input value for mayincome
var mayincome = document.getElementById("mayIncome").value;
// get input value for juneincome
var juneincome = document.getElementById("juneIncome").value;
// get input value for julyincome
var julyincome = document.getElementById("julyIncome").value;
// get input value for augustincome
var augustincome = document.getElementById("augustIncome").value;
// get input value for septemberincome
var septemberincome = document.getElementById("septemberIncome").value;
// get input value for octoberincome
var octoberincome = document.getElementById("octoberIncome").value;
// get input value for novemberincome
var novemberincome = document.getElementById("novemberIncome").value;
// get input value for decemberincome
var decemberincome = document.getElementById("decemberIncome").value;
return [januaryincome, februaryincome, marchincome, aprilincome, mayincome, juneincome, julyincome, augustincome, septemberincome, octoberincome, novemberincome, decemberincome];
}
function getExpenseValues() {
// get input value for januaryexpense
var januaryexpense = document.getElementById("januaryExpenses").value;
// get input value for februaryexpense
var februaryexpense = document.getElementById("februaryExpenses").value;
// get input value for marchexpense
var marchexpense = document.getElementById("marchExpenses").value;
// get input value for aprilexpense
var aprilexpense = document.getElementById("aprilExpenses").value;
// get input value for mayexpense
var mayexpense = document.getElementById("mayExpenses").value;
// get input value for juneexpense
var juneexpense = document.getElementById("juneExpenses").value;
// get input value for julyexpense
var julyexpense = document.getElementById("julyExpenses").value;
// get input value for augustexpense
var augustexpense = document.getElementById("augustExpenses").value;
// get input value for septemberexpense
var septemberexpense = document.getElementById("septemberExpenses").value;
// get input value for octoberexpense
var octoberexpense = document.getElementById("octoberExpenses").value;
// get input value for novemberexpense
var novemberexpense = document.getElementById("novemberExpenses").value;
// get input value for decemberexpense
var decemberexpense = document.getElementById("decemberExpenses").value;
return [januaryexpense, februaryexpense, marchexpense, aprilexpense, mayexpense, juneexpense, julyexpense, augustexpense, septemberexpense, octoberexpense, novemberexpense, decemberexpense];
}
// red: 'rgba(255, 99, 132, 0.2)', 'rgba(255, 99, 132, 1)',
// green: 'rgba(75, 192, 192, 0.2)', 'rgba(75, 192, 192, 1)',
// create chart js bar chart for id myChart
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
datasets: [
{
label: 'Income',
data: getExpenseValues(),
backgroundColor: [
'rgba(75, 192, 192, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(75, 192, 192, 0.2)',
],
borderColor: [
'rgba(75, 192, 192, 1)',
'rgba(75, 192, 192, 1)',
'rgba(75, 192, 192, 1)',
'rgba(75, 192, 192, 1)',
],
borderWidth: 1
},
{
label: 'Expenses',
data: getIncomeValues(),
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(255, 99, 132, 0.2)',
'rgba(255, 99, 132, 0.2)',
'rgba(255, 99, 132, 0.2)',
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(255, 99, 132, 1)',
'rgba(255, 99, 132, 1)',
'rgba(255, 99, 132, 1)',
],
borderWidth: 1
},
]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
// download function
document.getElementById("download").addEventListener("click", function () {
var canvas = document.getElementById("myChart");
var image = canvas.toDataURL("image/png");
var link = document.createElement('a');
link.download = "BucksChart.png";
link.href = image;
link.click();
});
// click handler for chart-tab
document.getElementById("chart-tab").addEventListener("click", function () {
myChart.data.datasets[0].data = getIncomeValues();
myChart.data.datasets[1].data = getExpenseValues();
// update chart
myChart.update();
});
};