File size: 3,148 Bytes
ad3cc5c | 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | document.addEventListener('DOMContentLoaded', function() {
// Initialize charts
initGenderChart();
initAgeChart();
});
function initGenderChart() {
const ctx = document.getElementById('genderChart').getContext('2d');
const genderChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Program A', 'Program B'],
datasets: [
{
label: 'Male',
data: [4215, 2517],
backgroundColor: '#3b82f6',
borderRadius: 4
},
{
label: 'Female',
data: [3627, 2099],
backgroundColor: '#10b981',
borderRadius: 4
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
stacked: false,
grid: {
display: false
}
},
y: {
stacked: false,
beginAtZero: true,
grid: {
drawBorder: false
}
}
},
plugins: {
legend: {
position: 'top',
},
tooltip: {
mode: 'index',
intersect: false,
}
}
}
});
}
function initAgeChart() {
const ctx = document.getElementById('ageChart').getContext('2d');
const ageChart = new Chart(ctx, {
type: 'line',
data: {
labels: ['0-9', '10-19', '20-29', '30-39', '40-49', '50-59', '60+'],
datasets: [{
label: 'Population by Age',
data: [1200, 1900, 3000, 2500, 1800, 1200, 858],
fill: true,
backgroundColor: 'rgba(59, 130, 246, 0.1)',
borderColor: '#3b82f6',
tension: 0.3,
pointBackgroundColor: '#3b82f6',
pointBorderColor: '#fff',
pointHoverRadius: 5,
pointHoverBackgroundColor: '#3b82f6',
pointHoverBorderColor: '#fff',
pointHitRadius: 10,
pointBorderWidth: 2
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
grid: {
drawBorder: false
}
},
x: {
grid: {
display: false
}
}
},
plugins: {
legend: {
display: false
}
}
}
});
}
// Responsive behavior for charts
window.addEventListener('resize', function() {
// Charts automatically handle resizing with responsive: true option
}); |