Skip to content

Commit c24e04f

Browse files
Maria PeterssonMaria Petersson
authored andcommitted
first steps with fetching repos and creating a chart
1 parent ded93a5 commit c24e04f

4 files changed

Lines changed: 74 additions & 0 deletions

File tree

code/chart.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,30 @@
22
const ctx = document.getElementById('chart').getContext('2d')
33

44
//"Draw" the chart here 👇
5+
const drawChart = (amount) => {
6+
7+
8+
const config = {
9+
type: 'doughnut',
10+
data: {
11+
labels: [
12+
'Finished projects',
13+
'Upcoming projects',
14+
'Yellow'
15+
],
16+
datasets: [{
17+
label: 'My First Dataset',
18+
data: [amount, 19-amount],
19+
backgroundColor: [
20+
'rgb(255, 99, 132)',
21+
'rgb(54, 162, 235)',
22+
'rgb(255, 205, 86)'
23+
],
24+
hoverOffset: 4
25+
}]
26+
},
27+
};
28+
29+
30+
const projectsChart = new Chart(ctx, config);
31+
}

code/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Project GitHub Tracker</title>
88
<link rel="stylesheet" href="./style.css" />
9+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
910
</head>
1011
<body>
1112
<h1>GitHub Tracker</h1>

code/script.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const USER = 'hejmaria'
2+
const REPOS_URL = `http://api.github.com/users/${USER}/repos`
3+
4+
const projectContainer = document.getElementById('projects')
5+
6+
7+
8+
const getRepos = () => {
9+
fetch(REPOS_URL)
10+
.then(res => res.json())
11+
.then(data => {
12+
console.log('The data', data)
13+
data.forEach (repo => console.log(repo.name))
14+
const forkedRepos = data.filter(repo => repo.fork && repo.name.startsWith('project-'))
15+
forkedRepos.forEach(repo => console.log(repo.name))
16+
17+
forkedRepos.forEach(repo => projectContainer.innerHTML += `<h3>${repo.name}</h3>`)
18+
19+
//make into a div or something to style them
20+
drawChart(forkedRepos.length)
21+
});
22+
23+
}
24+
25+
getRepos();
26+
27+
//const drawChart = (amoun

fromLesson.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const USER = 'hejmaria'
2+
const REPOS_URL = `http://api.github.com/users/${USER}/repos`
3+
4+
const getRepos = () => {
5+
fetch (REPOS_URL)
6+
.then (res => res.json())
7+
.then(data => {
8+
console.log(data)
9+
//data.forEach (repo => console.log(repo.name))
10+
const forkedRepos = data.fillter(repo => repo.fork && repo.name.startsWith('procet-'))
11+
forkedRepos.forEach(repo => console.log(repo.name))
12+
forkedRepos.forEach(repo => projectsContainer.inneHTML += `<h3>${repo.name}</h3>`)
13+
//make into a div or something to style them
14+
drawChart(forkedRepos.length)
15+
});
16+
17+
}
18+
19+
const drawChart = (amount) =>

0 commit comments

Comments
 (0)