YES YES THE DATA DISPLAYS

This commit is contained in:
2023-04-20 23:48:33 -05:00
parent e9c36d7473
commit 752ce96376
2 changed files with 37 additions and 6 deletions

View File

@@ -57,6 +57,7 @@
</form> </form>
</form> </form>
<div id="grades" value="invisible"> <div id="grades" value="invisible">
<!--Bar graph stuff-->
<canvas id="gradeBar" style="width:100%;max-width:700px"></canvas> <canvas id="gradeBar" style="width:100%;max-width:700px"></canvas>
</div> </div>
</div> </div>

42
main.js
View File

@@ -4,6 +4,7 @@ var barChart = document.querySelector('#grades');
if(barChart.getAttribute('value') == 'invisible'){ if(barChart.getAttribute('value') == 'invisible'){
barChart.style.display = 'none'; barChart.style.display = 'none';
} }
/* /*
Parse the name Parse the name
*/ */
@@ -37,7 +38,7 @@ async function PapaParse(department, num, name) {
cData = data; cData = data;
}) })
.then(() => { .then(() => {
console.log(cData); // console.log(cData);
}); });
// await fetch('/data/2022 Fall.json') // await fetch('/data/2022 Fall.json')
// .then(res => res.json()) // .then(res => res.json())
@@ -77,11 +78,40 @@ async function PapaParse(department, num, name) {
// console.log(selectedClass[i]["Count of letter grade"]); // console.log(selectedClass[i]["Count of letter grade"]);
} }
console.log(gradeDist); console.log(gradeDist);
loadChart(gradeDist);
barChart.style.display = ''; barChart.style.display = '';
} }
const myChart = new Chart("gradeBar", { function loadChart(gradeDist) {
type: "bar", const ctx = document.getElementById("gradeBar");
data: {}, new Chart(ctx, {
options: {} type: 'bar',
}); data: {
labels: [
'A',
'A-',
'B+',
'B',
'B-',
'C+',
'C',
'C-',
'D+',
'D',
'D-',
'F'],
datasets: [{
label: 'Grade Distribution',
data: Object.values(gradeDist),
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
}