-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (63 loc) · 2.63 KB
/
script.js
File metadata and controls
70 lines (63 loc) · 2.63 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
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
function loadCSV(file, tableId, headId, bodyId) {
fetch(file)
.then(response => response.text())
.then(data => {
const parsed = Papa.parse(data, { skipEmptyLines: true });
const rows = parsed.data;
const [headers, ...entries] = rows;
document.getElementById(headId).innerHTML = '';
document.getElementById(bodyId).innerHTML = '';
const thead = document.getElementById(headId);
headers.forEach(h => {
const th = document.createElement('th');
th.textContent = h;
thead.appendChild(th);
});
const tbody = document.getElementById(bodyId);
entries.forEach(row => {
const tr = document.createElement('tr');
row.forEach(cell => {
const td = document.createElement('td');
td.textContent = cell;
tr.appendChild(td);
});
tbody.appendChild(tr);
});
$(`#${tableId}`).DataTable();
if (chartId) {
const labels = entries.map(row => row[labelIndex]);
const dataPoints = entries.map(row => Number(row[dataIndex]));
const ctx = document.getElementById(chartId).getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: headers[dataIndex],
data: dataPoints,
backgroundColor: 'rgba(58, 175, 169, 0.5)',
borderColor: 'rgba(58, 175, 169, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: { beginAtZero: true }
}
}
});
}
});
}
document.addEventListener("DOMContentLoaded", () => {
if (document.getElementById('CIETable')) {
loadCSV('CIE.csv', 'CIETable', 'CIE-head', 'CIE-body', 'CIEChart');
}
if (document.getElementById('EdexcelTable')) {
loadCSV('Edexcel.csv', 'EdexcelTable', 'Edexcel-head', 'Edexcel-body','EdexcelChart');
}
if (document.getElementById('OxfordAqaTable')) {
loadCSV('OxfordAqa.csv', 'OxfordAqaTable', 'OxfordAqa-head', 'OxfordAqa-body','OxfordAqaChart');
}
});