|
| 1 | +const topicHoursGraph_el = document.getElementById('topicHoursGraph'); |
| 2 | +const ctxTopicHours = topicHoursGraph_el.getContext('2d'); |
| 3 | +let weekCompareGraph; // Variable to store the chart instance |
| 4 | + |
| 5 | +function getRandomNumber(min, max) { |
| 6 | + return (Math.random() * (max - min) + min).toFixed(1); |
| 7 | +} |
| 8 | + |
| 9 | +function createWeekCompare() { |
| 10 | + const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; |
| 11 | + const previousWeekHours = days.map(() => getRandomNumber(0.5, 8)); |
| 12 | + const currentWeekHours = days.map(() => getRandomNumber(0.5, 8)); |
| 13 | + |
| 14 | + return new Chart(ctxTopicHours, { |
| 15 | + type: 'line', |
| 16 | + data: { |
| 17 | + labels: days, |
| 18 | + datasets: [{ |
| 19 | + label: 'Previous Week', |
| 20 | + data: previousWeekHours, |
| 21 | + borderColor: 'rgba(169, 169, 169, 0.1)', |
| 22 | + backgroundColor: 'rgba(255, 99, 132, 0)', |
| 23 | + borderWidth: 2, |
| 24 | + fill: false // No fill under the line |
| 25 | + }, |
| 26 | + { |
| 27 | + label: 'Current Week', |
| 28 | + data: currentWeekHours, |
| 29 | + borderColor: 'rgba(54, 162, 235, 1)', |
| 30 | + backgroundColor: 'rgba(54, 162, 235, 0)', |
| 31 | + borderWidth: 2, |
| 32 | + fill: false // No fill under the line |
| 33 | + }] |
| 34 | + }, |
| 35 | + options: { |
| 36 | + plugins: { |
| 37 | + title: { |
| 38 | + display: true, |
| 39 | + text: 'Weekly Hours Comparison', |
| 40 | + }, |
| 41 | + legend: { |
| 42 | + display: false // Hide legend |
| 43 | + } |
| 44 | + }, |
| 45 | + maintainAspectRatio: false, |
| 46 | + responsive: true, |
| 47 | + scales: { |
| 48 | + y: { |
| 49 | + display: true, // Display y-axis |
| 50 | + ticks: { |
| 51 | + stepSize: 1, // Step size for y-axis ticks |
| 52 | + font: { |
| 53 | + size: 12 // Adjust font size for y-axis ticks |
| 54 | + } |
| 55 | + } |
| 56 | + }, |
| 57 | + x: { |
| 58 | + display: false // Hide x-axis |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + }); |
| 63 | +} |
| 64 | + |
| 65 | +// Initial setup |
| 66 | +weekCompareGraph = createWeekCompare(); |
0 commit comments