Student Demographics Dashboard
Overall Demographics Summary
Total Students
0
Average Age
0
Male Students
0
Female Students
0
Gender Distribution
Grade Level Distribution
Ethnicity Distribution
Detailed Student List
| ID | Name | Age | Gender | Grade Level | Ethnicity |
|---|
Add/Edit Students
Manage Existing Students
| ID | Name | Age | Gender | Grade Level | Ethnicity | Actions |
|---|
No data to display.
'; return; } // Sort data by count descending for better visualization const sortedData = Object.entries(data).sort(([, countA], [, countB]) => countB - countA); sortedData.forEach(([label, count]) => { const percentage = ((count / totalCount) * 100).toFixed(1); const barWrapper = document.createElement('div'); barWrapper.classList.add('chart-bar-wrapper'); barWrapper.innerHTML = ` ${label}:
${count} (${percentage}%)
`;
targetElement.appendChild(barWrapper);
});
}
/**
* Calculates and renders all distribution charts.
*/
function renderDistributionCharts() {
const totalStudents = students.length;
// Gender Distribution
const genderCounts = students.reduce((acc, student) => {
acc[student.gender] = (acc[student.gender] || 0) + 1;
return acc;
}, {});
renderBarChart(genderDistributionChartElem, genderCounts, totalStudents);
// Grade Level Distribution
const gradeOrder = ["Kindergarten", "1st Grade", "2nd Grade", "3rd Grade", "4th Grade", "5th Grade",
"6th Grade", "7th Grade", "8th Grade", "9th Grade", "10th Grade", "11th Grade",
"12th Grade", "College"];
const gradeCounts = {};
gradeOrder.forEach(grade => gradeCounts[grade] = 0); // Initialize all grades to 0
students.forEach(student => {
if (gradeCounts.hasOwnProperty(student.grade)) {
gradeCounts[student.grade]++;
}
});
// Filter out grades with 0 count for display, but keep order
const filteredGradeCounts = Object.fromEntries(
Object.entries(gradeCounts).filter(([, count]) => count > 0)
);
renderBarChart(gradeDistributionChartElem, filteredGradeCounts, totalStudents);
// Ethnicity Distribution
const ethnicityCounts = students.reduce((acc, student) => {
acc[student.ethnicity] = (acc[student.ethnicity] || 0) + 1;
return acc;
}, {});
renderBarChart(ethnicityDistributionChartElem, ethnicityCounts, totalStudents);
}
/**
* Generates a PDF of the dashboard content.
* Excludes non-essential UI elements like buttons and input forms.
*/
function generatePdf() {
// Create a temporary div to hold only the content for PDF
const pdfContentWrapper = document.createElement('div');
pdfContentWrapper.classList.add('pdf-content-wrapper'); // Apply PDF-specific styles
// Add title
const title = document.createElement('h2');
title.textContent = 'Student Demographics Dashboard Report';
title.classList.add('text-2xl', 'font-bold', 'mb-4');
pdfContentWrapper.appendChild(title);
// Add summary cards
const summarySection = document.createElement('div');
summarySection.classList.add('grid', 'grid-cols-4', 'gap-4', 'mb-6');
summarySection.innerHTML = `
Total Students
${totalStudentsCountElem.textContent}
Average Age
${averageAgeElem.textContent}
Male Students
${maleStudentsCountElem.textContent}
Female Students
${femaleStudentsCountElem.textContent}
Gender Distribution
Grade Level Distribution
Ethnicity Distribution
Detailed Student List
| ID | Name | Age | Gender | Grade Level | Ethnicity |
|---|
