-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoughnutchart.js
69 lines (60 loc) · 1.42 KB
/
doughnutchart.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
var personName = [],
privateWorthData = [];
async function dummyChart() {
await getDummyData();
let ctx = document.getElementById("doughnutchart").getContext("2d");
let chart = new Chart(ctx, {
// The type of chart we want to create
type: "doughnut",
// The data for our dataset
data: {
labels: personName,
datasets: [
{
barPercentage: 1.0,
fill: false,
borderRadius: 0,
tension: 0.5,
label: "Private worth",
backgroundColor: ['#FFB1C1','#FFE6AA','#9AD0F5','#EBE0FF','#DBF2F2'],
borderColor: "#F09397",
scaleFontColor:"black",
data: privateWorthData,
},
],
},
// Configuration options go here
options: {
scales: {
x: {
display: false,
grid: {
display: false,
},
},
y: {
display: false,
grid: {
display: false,
},
},
},
cornerRadius: 5,
responsive: true,
maintainAspectRatio: false,
},
});
}
dummyChart();
//Fetch Data from API
async function getDummyData() {
const apiUrl = "https://forbes400.herokuapp.com/api/forbes400?limit=5";
const response = await fetch(apiUrl);
const barChatData = await response.json();
console.log(barChatData);
const name = barChatData.map((x) => x.personName);
console.log(name);
const pvtworth = barChatData.map((x) => x.privateAssetsWorth);
privateWorthData = pvtworth;
personName = name;
}