-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
42 lines (40 loc) · 1.35 KB
/
scripts.js
File metadata and controls
42 lines (40 loc) · 1.35 KB
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
// Fetch and display the top repositories
fetch('./data/metrics.json')
.then(response => response.json())
.then(data => {
// Prepare data for Chart.js
const labels = Object.keys(data);
const starCounts = Object.values(data);
// Populate the chart
const ctx = document.getElementById('repoContributions').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Stars',
data: starCounts,
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
// Populate the table
const tableBody = document.querySelector('#data-table tbody');
labels.forEach((repo, index) => {
const row = document.createElement('tr');
row.innerHTML = `<td>${repo}</td><td>${starCounts[index]}</td>`;
tableBody.appendChild(row);
});
})
.catch(error => {
console.error('Error fetching or processing data:', error);
});