-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
57 lines (45 loc) · 1.31 KB
/
app.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
var employeeLabel = [], employeeSalaryData = [], employeeAgeData = []
async function dummyChart() {
await getDummyData()
const ctx = document.getElementById('myChart').getContext('2d');
const chart = new Chart(ctx, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: employeeLabel,
datasets: [{
label: 'Employee Salary',
backgroundColor: 'blue',
borderColor: 'rgb(255, 99, 132)',
data: employeeSalaryData
},
{
label: 'Employee Age',
backgroundColor: 'pink',
borderColor: 'rgb(255, 99, 132)',
data: employeeAgeData
}
]
},
// Configuration options go here
options: {
tooltips: {
mode: 'index'
}
}
})}
dummyChart()
//Fetch Data from API
async function getDummyData() {
const apiUrl = "http://dummy.restapiexample.com/api/v1/employees"
const response = await fetch(apiUrl)
const barChatData = await response.json()
const salary = barChatData.data.map((x) => x.employee_salary)
console.log(salary)
const age = barChatData.data.map((x) => x.employee_age)
const name = barChatData.data.map((x) => x.employee_name)
employeeSalaryData = salary
employeeAgeData = age
employeeLabel = name
}