-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathareachart.js
70 lines (61 loc) · 1.38 KB
/
areachart.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
var personName = [],
privateWorthData = [];
async function dummyChart() {
await getDummyData();
let ctx = document.getElementById("areachart").getContext("2d");
let chart = new Chart(ctx, {
// The type of chart we want to create
type: "line",
// The data for our dataset
data: {
labels: personName,
datasets: [
{
barPercentage: 1.0,
fill: true, //for area chart fill: true karna important hai
borderRadius: 5,
tension: 0.5,
label: "Private worth",
backgroundColor: "#FFB1C1",
data: privateWorthData,
},
],
},
// Configuration options go here
options: {
elements: {
point:{
radius: 1.5
}
},
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 pvtworth = barChatData.map((x) => x.privateAssetsWorth);
privateWorthData = pvtworth;
personName = name;
}