-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.js
137 lines (132 loc) · 4.34 KB
/
javascript.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
134
135
136
137
var label = [];
var sample_data = '';
$.getJSON("data.json", function (data) {
sample_data = data;
console.log(sample_data);
const days = data.map((object) => {
return object["day"];
});
const amount = data.map((object) => {
return object["amount"];
});
console.log(days);
console.log(amount);
const ctx = document.getElementById('myChart').getContext('2d');
const myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: days,
datasets: [{
//label: 'Spending - Last 7 days',
data: amount,
backgroundColor: [
'hsl(10, 79%, 65%)',
'hsl(10, 79%, 65%)',
'hsl(186, 34%, 60%)',
'hsl(10, 79%, 65%)',
'hsl(10, 79%, 65%)',
'hsl(10, 79%, 65%)',
'hsl(10, 79%, 65%)'
],
// borderColor: [
// 'hsl(10, 79%, 65%)',
// 'hsl(10, 79%, 65%)',
// 'hsl(186, 34%, 60%)',
// 'hsl(10, 79%, 65%)',
// 'hsl(10, 79%, 65%)',
// 'hsl(10, 79%, 65%)'
// ],
hoverBackgroundColor: [
'hsl(10, 79%, 65%, 0.5)',
'hsl(10, 79%, 65%, 0.5)',
'hsl(186, 34%, 60%,0.5)',
'hsl(10, 79%, 65%, 0.5)',
'hsl(10, 79%, 65%, 0.5)',
'hsl(10, 79%, 65%, 0.5)',
'hsl(10, 79%, 65%, 0.5)'
],
borderWidth: 1,
borderRadius: 5,
borderSkipped: false
}]
},
// options: {
// scales: {
// y: {
// beginAtZero: true
// }
// }
// }
//This is the config part. removes the gridlines at the background of the chart.
options : {
plugins: {
tooltip: {
//Removes the little color box in the tooltip
displayColors: false,
backgroundColor: 'hsl(25, 47%, 15%)',
callbacks: {
// title: (context) => {
// console.log(context);
// return;
// },
title: (item) => {
return;
},
label: (item, everything) => {
console.log(item);
let amountinDollar = item.raw;
let label = "$" + amountinDollar;
console.log(label);
return label;
},
body: (context) => {
console.log(context);
return "$" + context;
}
}
},
//the legend removes the legend key at the top of the chart
legend: {
display:false,
},
},
scales: {
x: {
grid: {
display: false,
drawBorder: false
},
ticks: {
color: "hsl(28, 10%, 53%)"
}
},
y: {
grid: {
display: false,
//drawBorder completely removes the y and x axis line
drawBorder: false,
beginAtZero: true
// color: 'rgba(217,143,7,0.1)',
},
ticks: {
display: false
}
}
}
}
});
});
// let options = {
// scales: {
// xAxes: [{
// gridLines: {
// display:false
// }
// }],
// yAxes: [{
// gridLines: {
// display:false
// }
// }]
// }
// }