Best-Seller Ranking Tracker

Best-Seller Ranking Tracker

Monitor product rankings and analyze sales performance.

Total Products Tracked

0

Average Rank Change

0

Top Mover

N/A

Product Rankings

Rank Product Sales Volume

Top 5 Products by Sales

Best-Seller Performance Report

Report Date:

Performance Rankings

RankChangeProductCategorySales Volume ($)

Top 5 Products by Sales

Top 5 Products by Sales Chart

${p.category}

${formatUSD(p.sales)} `); }); renderChart(sortedProducts); } function renderChart(sortedProducts) { const ctx = document.getElementById('sales-chart').getContext('2d'); const top5 = [...sortedProducts].sort((a,b) => b.sales - a.sales).slice(0, 5); const labels = top5.map(p => p.name); const data = top5.map(p => p.sales); if (salesChart) salesChart.destroy(); salesChart = new Chart(ctx, { type: 'bar', data: { labels, datasets: [{ label: 'Sales Volume ($)', data, backgroundColor: '#3b82f6', borderColor: '#2563eb', borderWidth: 1 }] }, options: { responsive: true, plugins: { legend: { display: false } }, scales: { y: { beginAtZero: true, ticks: { callback: v => formatUSD(v) } } } } }); } function renderProductList() { const list = document.getElementById('product-list'); list.innerHTML = ''; products.forEach(p => { list.insertAdjacentHTML('beforeend', `
${p.name} (Rank: ${p.currentRank})
`); }); } // --- FORMS & EVENT HANDLERS --- productForm.addEventListener('submit', (e) => { e.preventDefault(); const data = { name: document.getElementById('product-name').value, category: document.getElementById('product-category').value, currentRank: parseInt(document.getElementById('product-current-rank').value), prevRank: parseInt(document.getElementById('product-prev-rank').value), sales: parseFloat(document.getElementById('product-sales').value), }; if (editingProductId) { const product = products.find(p => p.id === editingProductId); Object.assign(product, data); } else { data.id = Date.now(); products.push(data); } resetForm(); renderAll(); }); document.getElementById('cancel-edit-btn').addEventListener('click', resetForm); document.getElementById('product-list').addEventListener('click', (e) => { if (e.target.classList.contains('product-edit')) setupEditForm(parseInt(e.target.dataset.id)); if (e.target.classList.contains('product-delete')) deleteProduct(parseInt(e.target.dataset.id)); }); function resetForm() { productForm.reset(); editingProductId = null; document.getElementById('form-title').textContent = 'Add New Product'; document.getElementById('cancel-edit-btn').style.display = 'none'; } function setupEditForm(id) { const p = products.find(p => p.id === id); if (!p) return; document.getElementById('product-id').value = p.id; document.getElementById('product-name').value = p.name; document.getElementById('product-category').value = p.category; document.getElementById('product-current-rank').value = p.currentRank; document.getElementById('product-prev-rank').value = p.prevRank; document.getElementById('product-sales').value = p.sales; editingProductId = id; document.getElementById('form-title').textContent = 'Edit Product'; document.getElementById('cancel-edit-btn').style.display = 'inline-block'; } function deleteProduct(id) { if (confirm('Delete this product?')) { products = products.filter(p => p.id !== id); renderAll(); } } downloadPdfBtn.addEventListener('click', generatePdf); // --- TABS & NAVIGATION --- window.switchTab = (tabName) => { currentTab = tabName; Object.values(tabBtns).forEach(b=>b.classList.replace('tab-active', 'tab-inactive')); Object.values(tabContents).forEach(c=>c.style.display='none'); tabBtns[tabName].classList.replace('tab-inactive', 'tab-active'); tabContents[tabName].style.display = 'block'; }; window.navigateTabs = (dir) => { if (dir==='next' && currentTab==='dashboard') switchTab('config'); else if (dir==='prev' && currentTab==='config') switchTab('dashboard'); }; // --- PDF GENERATION --- async function generatePdf() { const { jsPDF } = window.jspdf; const pdfReportElement = document.getElementById('pdf-report'); const sortedProducts = [...products].sort((a, b) => a.currentRank - b.currentRank); document.getElementById('pdf-date').textContent = new Date().toLocaleDateString('en-US'); const pdfTableBody = document.getElementById('pdf-table-body'); pdfTableBody.innerHTML = ''; sortedProducts.forEach(p => { const change = p.prevRank - p.currentRank; let changeText = '-'; if (change > 0) changeText = `+${change}`; if (change < 0) changeText = `${change}`; pdfTableBody.insertAdjacentHTML('beforeend', `${p.currentRank}${changeText}${p.name}${p.category}${p.sales.toLocaleString()}`); }); document.getElementById('pdf-chart-image').src = salesChart.toBase64Image(); const canvas = await html2canvas(pdfReportElement, { scale: 2 }); const imgData = canvas.toDataURL('image/jpeg', 0.85); const pdf = new jsPDF('p', 'mm', 'a4'); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, pdfHeight); pdf.save('Best-Seller-Report.pdf'); } // --- INITIALIZATION --- function init() { products = [ { id: 1, name: 'Smart Home Hub X', category: 'Electronics', currentRank: 1, prevRank: 2, sales: 250000 }, { id: 2, name: 'Pro-Gamer Mouse', category: 'Electronics', currentRank: 2, prevRank: 1, sales: 225000 }, { id: 3, name: 'Organic Green Tea', category: 'Groceries', currentRank: 3, prevRank: 5, sales: 180000 }, { id: 4, name: 'Luxury Yoga Mat', category: 'Sports', currentRank: 4, prevRank: 3, sales: 175000 }, { id: 5, name: 'SilentRead E-Reader', category: 'Electronics', currentRank: 5, prevRank: 7, sales: 150000 } ]; renderAll(); } init(); });
Scroll to Top