Skip to content

Commit c35466b

Browse files
Kara HowesKara Howes
authored andcommitted
fixed bug with displaying chart and array
1 parent 30f6326 commit c35466b

4 files changed

Lines changed: 27 additions & 34 deletions

File tree

code/chart.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@ const drawChart = (amount) =>{
1010
labels: [
1111
'Completed Projects',
1212
'Remaining Projects',
13-
1413
],
1514
datasets: [{
1615
label: 'My First Dataset',
1716
data: [amount , 24-amount],
1817
backgroundColor: [
1918
'rgb(255, 99, 132)',
20-
'rgb(54, 162, 235)',
19+
'rgb(54, 162, 235)'
2120

2221
],
2322
hoverOffset: 4
2423
}]
25-
}
24+
},
2625

27-
}
28-
const myChart = new Chart(ctx, config);
26+
};
27+
const myChart = new Chart(ctx, config)
2928
}
3029

3130

code/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h2>Projects:</h2>
1717
</main>
1818

1919
<!-- This will be used to draw the chart 👇 -->
20-
<canvas id="chart" class="chart"></canvas>
20+
<canvas id="chart" class="canvas-chart"></canvas>
2121

2222
<script src="./script.js"></script>
2323
<script src="./chart.js"></script>

code/script.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,27 @@ const USER = 'KaraHowes'
22
const repoURL = `https://api.github.com/users/${USER}/repos`
33
const projectsContainer = document.getElementById('projects')
44

5-
6-
7-
fetch(repoURL)
8-
.then((response)=>{
9-
return response.json()
10-
})
11-
.then((data)=>{
12-
console.log(data)
13-
projectsContainer.innerHTML = `The name of your first project was ${data[0].name}`
5+
const getRepos = ()=>{
6+
7+
fetch(repoURL)
8+
.then(response => response.json())
9+
.then(data => {
10+
console.log(data)
11+
//projectsContainer.innerHTML = `The name of your first project was ${data[0].name}`
12+
13+
14+
const forkedProjects = data.filter(repo => repo.fork && repo.name.startsWith('project-'))
15+
forkedProjects.forEach(repo => projectsContainer.innerHTML += `<h3>${repo.name}</h3>`)
1416

15-
const forkedProjects = data.filter(repo => repo.fork && repo.name.startsWith('project-'))
17+
drawChart(forkedProjects.length)
18+
console.log('hello', forkedProjects.length)
1619

17-
forkedProjects.forEach((forkName)=> {
18-
projectsContainer.innerHTML += `<p>${forkName.name}</p>`
19-
20-
drawChart(forkedProjects.length)
21-
console.log('hello', forkedProjects.length)
22-
20+
21+
22+
}
2323

24-
})
24+
25+
)
2526
}
2627

27-
//repo.forEach((reponames) => {
28-
//projects.innerHTML += `<p> Project name: ${reponames.name}</p>`
29-
//});
30-
31-
32-
33-
).catch((error) => console.error(error))
34-
.then(() => console.log('Request finished'));
28+
getRepos()

code/style.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ body {
22
background-color: aquamarine;
33
}
44

5-
.chart{
6-
max-width: 100px;
7-
height: 300px;
5+
.canvas-chart{
6+
max-width: 500px;
7+
88
}

0 commit comments

Comments
 (0)