document.addEventListener('DOMContentLoaded', function() { // Sample data (would be replaced with API call in production) const salesData = [ { date: '1/6/18', region: 'East', manager: 'Martha', salesperson: 'Alexander', item: 'Television', units: 95, price: 1198, amount: 113810 }, { date: '1/23/18', region: 'Central', manager: 'Hermann', salesperson: 'Shelli', item: 'Home Theater', units: 50, price: 500, amount: 25000 }, // ... rest of the data from the provided dataset ]; // Populate table const tableBody = document.getElementById('salesTableBody'); salesData.forEach(sale => { const row = document.createElement('tr'); row.innerHTML = ` ${sale.date} ${sale.region} ${sale.manager} ${sale.salesperson} ${sale.item} ${sale.units} $${sale.price.toLocaleString()} $${sale.amount.toLocaleString()} `; tableBody.appendChild(row); }); // Initialize charts initCharts(); }); function initCharts() { // Sales Chart const salesCtx = document.getElementById('salesChart').getContext('2d'); new Chart(salesCtx, { type: 'line', data: { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], datasets: [{ label: 'Sales Amount', data: [138810, 74203, 67088, 119850, 247136, 137820, 55000, 42832, 13521, 45600, 9491.5, 84595], borderColor: '#4F46E5', backgroundColor: 'rgba(79, 70, 229, 0.1)', tension: 0.3, fill: true }] }, options: { responsive: true, plugins: { legend: { position: 'top', }, tooltip: { callbacks: { label: function(context) { return `$${context.raw.toLocaleString()}`; } } } }, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return '$' + value.toLocaleString(); } } } } } }); // Products Chart const productsCtx = document.getElementById('productsChart').getContext('2d'); new Chart(productsCtx, { type: 'doughnut', data: { labels: ['Television', 'Home Theater', 'Cell Phone', 'Video Games', 'Desk'], datasets: [{ data: [691402, 280500, 62550, 20500.5, 1250], backgroundColor: [ '#4F46E5', '#10B981', '#F59E0B', '#EF4444', '#8B5CF6' ], borderWidth: 1 }] }, options: { responsive: true, plugins: { legend: { position: 'right', }, tooltip: { callbacks: { label: function(context) { return `$${context.raw.toLocaleString()}`; } } } } } }); // Region Chart const regionCtx = document.getElementById('regionChart').getContext('2d'); new Chart(regionCtx, { type: 'bar', data: { labels: ['East', 'Central', 'West'], datasets: [ { label: 'Total Sales', data: [246601, 678339.5, 131379], backgroundColor: '#4F46E5', }, { label: 'Average Sale', data: [246601/10, 678339.5/20, 131379/5], backgroundColor: '#10B981', } ] }, options: { responsive: true, plugins: { legend: { position: 'top', }, tooltip: { callbacks: { label: function(context) { return `$${context.raw.toLocaleString()}`; } } } }, scales: { y: { beginAtZero: true, ticks: { callback: function(value) { return '$' + value.toLocaleString(); } } } } } }); }