-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
97 lines (85 loc) · 2.22 KB
/
main.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
const menuIcon = document.querySelector(".menu-icon");
const aside = document.querySelector(".aside");
const asideClose = document.querySelector(".aside_close-icon");
function toggle(el, className) {
if (el.classList.contains(className)) {
el.classList.remove(className);
} else {
el.classList.add(className);
}
}
menuIcon.addEventListener("click", function () {
toggle(aside, "active");
});
asideClose.addEventListener("click", function () {
toggle(aside, "active");
});
var personName = [],
netWorthData = [],
privateWorthData = [];
async function dummyChart() {
await getDummyData();
let ctx = document.getElementById("barchart").getContext("2d");
let chart = new Chart(ctx, {
// The type of chart we want to create
type: "bar",
// The data for our dataset
data: {
labels: personName,
datasets: [
{
barPercentage: 1.0,
borderRadius: 5,
tension: 0.5,
label: "Net worth",
backgroundColor: "#98BDFF",
borderColor: "rgb(255, 99, 132)",
data: netWorthData,
},
{
barPercentage: 1.0,
borderRadius: 5,
tension: 0.5,
label: "private worth",
backgroundColor: "#4B49AC",
borderColor: "rgb(255, 99, 132)",
data: privateWorthData,
},
],
},
// Configuration options go here
options: {
scales: {
x: {
grid: {
display: false,
},
},
y: {
grid: {
display: true,
},
},
},
cornerRadius: 5,
responsive: true,
maintainAspectRatio: false,
},
});
}
dummyChart();
//Fetch Data from API
async function getDummyData() {
const apiUrl = "https://forbes400.herokuapp.com/api/forbes400?limit=10";
const response = await fetch(apiUrl);
const barChatData = await response.json();
console.log(barChatData);
const name = barChatData.map((x) => x.personName);
console.log(name);
const networth = barChatData.map((x) => x.finalWorth);
console.log(networth);
const pvtworth = barChatData.map((x) => x.privateAssetsWorth);
netWorthData = networth;
privateWorthData = pvtworth;
personName = name;
}