-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfta-growth.html
174 lines (155 loc) · 5.94 KB
/
fta-growth.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trade Balance Before and After FTAs</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
.chart-container {
display: flex;
justify-content: space-between;
width: 90%;
margin: auto;
}
.side-panel {
width: 25%;
padding: 10px;
background-color: #f5f5f5;
border-left: 2px solid #ddd;
}
.side-panel h3 {
text-align: center;
margin-bottom: 10px;
}
.color-block {
display: flex;
align-items: center;
margin-bottom: 5px;
}
.color-block div {
width: 20px;
height: 20px;
margin-right: 10px;
}
.growth-label, .cagr-label {
font-size: 14px;
}
</style>
</head>
<body>
<div class="chart-container">
<div style="width: 75%;">
<canvas id="ftaChart"></canvas>
</div>
<!-- Side panel for showing CAGR and Growth -->
<div class="side-panel">
<h3>FTA Growth & CAGR</h3>
<div id="growthCagrList"></div>
</div>
</div>
<script>
const labels = [
"SAFTA (2006) Pre-FTA", "SAFTA (2006) Post-FTA",
"AIFTA (2009) Pre-FTA", "AIFTA (2009) Post-FTA",
"ISLFTA (2000) Pre-FTA", "ISLFTA (2000) Post-FTA",
"CECA Singapore (2005) Pre-FTA", "CECA Singapore (2005) Post-FTA",
"CEPA South Korea (2010) Pre-FTA", "CEPA South Korea (2010) Post-FTA",
"CEPA Japan (2011) Pre-FTA", "CEPA Japan (2011) Post-FTA",
"CECPA Mauritius (2021) Pre-FTA", "CECPA Mauritius (2021) Post-FTA",
"CEPA UAE (2022) Pre-FTA", "CEPA UAE (2022) Post-FTA",
"ECTA Australia (2022) Pre-FTA", "ECTA Australia (2022) Post-FTA",
"CECA Malaysia (2011) Pre-FTA", "CECA Malaysia (2011) Post-FTA",
"EHS Thailand (2004) Pre-FTA", "EHS Thailand (2004) Post-FTA"
];
const allData = [
202.93, 354.55, // SAFTA
-1667.11, -3084.13, // AIFTA
52.88, 50.64, // ISLFTA
229.68, 623.88, // CECA Singapore
-3219.94, -4236.73, // CEPA South Korea
-651.4, -2043.59, // CEPA Japan
42.43, 64.95, // CECPA Mauritius
-8605.45, -11816.63, // CEPA UAE
-8697.48, -12766.68, // ECTA Australia
-651.4, -2043.59, // CECA Malaysia
26.19, 49.58 // EHS Thailand
];
const colors = [
'#1f77b4', '#1f77b4', '#ff7f0e', '#ff7f0e', '#2ca02c', '#2ca02c', '#d62728', '#d62728',
'#9467bd', '#9467bd', '#8c564b', '#8c564b', '#e377c2', '#e377c2', '#7f7f7f', '#7f7f7f',
'#bcbd22', '#bcbd22', '#17becf', '#17becf', '#1f77b4', '#1f77b4'
];
const ctx = document.getElementById('ftaChart').getContext('2d');
const ftaChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Trade Balance (in million USD)',
data: allData,
backgroundColor: colors,
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: false
},
tooltip: {
callbacks: {
label: function(tooltipItem) {
return `${tooltipItem.label}: ${tooltipItem.raw.toFixed(2)} million USD`;
}
}
}
},
scales: {
x: {
ticks: {
maxRotation: 45,
minRotation: 45
}
},
y: {
beginAtZero: false,
title: {
display: true,
text: 'Trade Balance (in million USD)'
}
}
}
}
});
// Function to calculate Growth % and CAGR and display it in the side panel
function displayGrowthAndCagr() {
const growthCagrList = document.getElementById('growthCagrList');
for (let i = 1; i < allData.length; i += 2) {
const preValue = allData[i - 1];
const postValue = allData[i];
const growth = ((postValue - preValue) / Math.abs(preValue)) * 100; // Growth %
const n = 3; // Number of years for CAGR
const cagr = (((postValue / preValue) ** (1 / n)) - 1) * 100; // CAGR %
// Create the color block div
const colorBlock = document.createElement('div');
colorBlock.className = 'color-block';
const colorBox = document.createElement('div');
colorBox.style.backgroundColor = colors[i]; // Use the post-FTA bar color
colorBlock.appendChild(colorBox);
const label = document.createElement('span');
label.innerHTML = `
<span class="growth-label">Growth: ${growth.toFixed(2)}%</span><br>
<span class="cagr-label">CAGR: ${cagr.toFixed(2)}%</span>
`;
colorBlock.appendChild(label);
growthCagrList.appendChild(colorBlock);
}
}
// Call the function to display Growth and CAGR values in the side panel
displayGrowthAndCagr();
ftaChart.update();
</script>
</body>
</html>