-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal-trade-bargraph-white.js
187 lines (174 loc) · 7.07 KB
/
global-trade-bargraph-white.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
// Correlation data calculated (mockup, replace with real data)
const eventCorrelations = {
"Russia-Ukraine War": -0.6326,
"India-UAE CEPA & Israel-Hamas Conflict": -0.5587,
"9/11 Attacks": 0.1783,
"Kargil War": 0.1757,
"Arab Spring & Fukushima Nuclear Disaster": -0.0946,
"Abrogation of Article 370": -0.0604,
"Brexit & COVID-19 Pandemic": 0.0308,
"Modi's Economic Reforms & Collapse of Global Oil Prices": -0.0235,
"Taper Tantrum": -0.0207,
"Demonetization": 0.0195,
"Global Financial Crisis & Mumbai Attacks": 0.0063,
"China’s Economic Slowdown": 0.0040,
"Eurozone Debt Crisis": 0.0039
};
// // Extract event names and correlation values
// const eventLabels = Object.keys(eventCorrelations);
// const eventValues = Object.values(eventCorrelations);
// // Create the heatmap using Chart.js
// const ctx = document.getElementById('correlationChart').getContext('2d');
// const chart = new Chart(ctx, {
// type: 'bar', // Using a bar chart for simplicity
// data: {
// labels: eventLabels,
// datasets: [{
// label: 'Correlation with Trade Balance',
// data: eventValues,
// backgroundColor: eventValues.map(value => value > 0 ? 'rgba(75, 192, 192, 0.6)' : 'rgba(255, 99, 132, 0.6)'),
// borderColor: eventValues.map(value => value > 0 ? 'rgba(75, 192, 192, 1)' : 'rgba(255, 99, 132, 1)'),
// borderWidth: 1
// }]
// },
// options: {
// responsive: true,
// scales: {
// y: {
// beginAtZero: true,
// min: -1,
// max: 1,
// title: {
// display: true,
// text: 'Correlation Coefficient'
// }
// }
// },
// plugins: {
// title: {
// display: true,
// text: 'Correlation between Geopolitical Events and India\'s Trade Balance'
// }
// }
// }
// });
// // Extract event names and correlation values
// const eventLabels = Object.keys(eventCorrelations);
// const eventValues = Object.values(eventCorrelations);
// // Create the horizontal bar chart using Chart.js
// const ctx = document.getElementById('correlationChart').getContext('2d');
// const chart = new Chart(ctx, {
// type: 'bar',
// data: {
// labels: eventLabels,
// datasets: [{
// label: 'Correlation with Trade Balance',
// data: eventValues,
// backgroundColor: eventValues.map(value => value > 0 ? 'rgba(75, 192, 192, 0.6)' : 'rgba(255, 99, 132, 0.6)'),
// borderColor: eventValues.map(value => value > 0 ? 'rgba(75, 192, 192, 1)' : 'rgba(255, 99, 132, 1)'),
// borderWidth: 1
// }]
// },
// options: {
// indexAxis: 'y', // This makes it a horizontal bar chart
// responsive: true,
// scales: {
// x: {
// beginAtZero: true,
// min: -1,
// max: 1,
// ticks: {
// color: '#ffffff' // White x-axis labels
// },
// title: {
// display: true,
// text: 'Correlation Coefficient',
// color: '#ffffff' // White axis title
// }
// },
// y: {
// ticks: {
// color: '#ffffff' // White y-axis labels
// }
// }
// },
// plugins: {
// title: {
// display: true,
// text: 'Correlation between Geopolitical Events and India\'s Trade Balance',
// color: '#ffffff' // White chart title
// },
// legend: {
// labels: {
// color: '#ffffff' // White legend labels
// }
// }
// }
// }
// });
// Extract event names and correlation values
const eventLabels = Object.keys(eventCorrelations);
const eventValues = Object.values(eventCorrelations);
// Separate positive and negative values
const positiveEventValues = eventValues.map(value => value > 0 ? value : 0);
const negativeEventValues = eventValues.map(value => value < 0 ? value : 0);
// Create the horizontal bar chart using Chart.js
const ctx = document.getElementById('correlationChart').getContext('2d');
const chart = new Chart(ctx, {
type: 'bar',
data: {
labels: eventLabels,
datasets: [
{
label: 'Positive Correlation',
data: positiveEventValues,
backgroundColor: 'rgba(75, 192, 192, 0.6)', // Green for positive values
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 3
},
{
label: 'Negative Correlation',
data: negativeEventValues,
backgroundColor: 'rgba(255, 99, 132, 0.6)', // Red for negative values
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 3
}
]
},
options: {
indexAxis: 'y', // This makes it a horizontal bar chart
responsive: true,
scales: {
x: {
beginAtZero: true,
min: -0.8,
max: 0.6,
ticks: {
color: '#000' // White x-axis labels
},
title: {
display: true,
text: 'Correlation Coefficient',
color: '#000' // White axis title
}
},
y: {
ticks: {
color: '#000' // White y-axis labels
}
}
},
plugins: {
title: {
display: true,
text: 'Correlation between Geopolitical Events and India\'s Trade Balance',
color: '#000' // White chart title
},
legend: {
labels: {
color: '#000' // White legend labels
}
}
}
}
});