-
Notifications
You must be signed in to change notification settings - Fork 0
/
charts.js
215 lines (196 loc) · 4.89 KB
/
charts.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
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
$(document).ready(function() {
let myChart = document.getElementById('myChart').getContext('2d');
Chart.defaults.global.defaultFontFamily = 'Lato';
Chart.defaults.global.defaultFontSize = 12;
Chart.defaults.global.defaultFontColor = '#777';
let massPopCart;
let data1 = [];
let data2 = [];
let data3 = [];
// to view data,go to file processedData.
data1 = combinedArray2;
data2 = dataAllTroughPrices;
data3 = velocityDataAll;
callChart(); //default chart view(ALL)
//method to load chart data depending on button clicked
$('#button1').click(function() {
$('#button1').removeClass("selected");
$(this).addClass("selected");
data1 = dataPeakPrices20102013;
data2 = dataTroughPrices20102013;
data3 = velocityData20102013;
if (massPopCart != null) {
massPopCart.destroy(); //clear previous chart
}
callChart();
});
$('#button2').click(function() {
$('#button2').removeClass("selected"); //highlight button color
$(this).addClass("selected"); //unhighlight button color
data1 = dataPeakPrices20132017;
data2 = dataTroughPrices20132017;
data3 = velocityData20132017;
if (massPopCart != null) {
massPopCart.destroy(); //clear previous chart canvas
}
callChart();
});
// $('#button3').click(function() {
// $('#button3').removeClass("selected");
// $(this).addClass("selected");
// data1 = dataPeakPrices2018Now;
// data2 = dataTroughPrices2018Now;
// data3 = veloctityData2018Now;
// if (massPopCart != null) {
// massPopCart.destroy();
// }
// callChart();
// });
$('#buttonAll').click(function() {
$('#buttonAll').removeClass("selected");
$(this).addClass("selected");
data1 = dataAllPeakPrices;
data2 = dataAllTroughPrices;
data3 = velocityDataAll;
if (massPopCart != null) {
massPopCart.destroy(); //clear previous chart
}
callChart();
});
function callChart() {
massPopCart = new Chart(myChart, {
type: 'bar',
data: {
datasets: [{
fill: '0',
data: data1,
showLine: true,
label: 'Peak',
backgroundColor: '#7FDBFF',
pointHoverBackgroundColor: 'red',
borderWidth: 2,
borderColor: "#7FDBFF",
pointRadius: '2',
type: 'line',
},
{
fill: 'start',
data: data2,
type: 'line',
hidden: true,
label: 'Trough',
labelColor: 'pink',
backgroundColor: 'pink',
color: "rgba(255,255,255,0)",
borderWidth: 2,
borderColor: "lightgray",
pointRadius: '2.3',
pointHoverBackgroundColor: 'red',
},
{
yAxisID: "id2",
fill: 'origin',
data: data3,
label: 'Velocity',
backgroundColor: 'grey',
fontFamily: "Quicksand",
fillColor: "#4e8eb1",
borderWidth: .9,
borderColor: "grey",
}
]
},
options: {
scales: {
xAxes: [{
barPercentage: .02,
ticks: {
fontFamily: "Quicksand",
fontSize: 15,
fontColor: "gray",
},
display: true,
gridLines: {
display: false,
},
type: 'time',
distribution: 'logarithmic',
time: {
displayFormats: {
unit: 'month'
}
}
}],
yAxes: [{
tooltips: {
enabled: true,
},
ticks: {
display: true,
min: 0,
max: 23000,
mirror: true,
fontFamily: "Quicksand",
fontSize: 12,
fontColor: "white",
callback: function(value) {
return '$' + value.toFixed(2);
}
},
gridLines: {
display: false,
drawBorder: false,
},
position: 'left',
type: "logarithmic",
scaleLabel: {
display: true,
labelString: 'USD',
},
id: "price"
}, {
scaleLabel: {
display: false,
labelString: '% change',
},
type: "linear",
position: "right",
gridLines: {
display: false,
},
display: false,
ticks: {
min: -1300,
max: 4000,
mirror: true,
fontFamily: "Quicksand",
fontSize: 12,
},
id: "id2"
}]
},
title: {
position: 'bottom',
display: true,
fontFamily: "Quicksand",
text: 'Bitcoin Life Cycles',
fontSize: 21,
fontColor: 'grey'
},
legend: {
position: 'left',
fontFamily: "Quicksand",
fontSize: 12,
fontColor: "lightgray"
},
layout: {
padding: {
top: 0,
left: 0,
bottom: 0
}
},
}
});
}
})