Product Demand Forecasting Dashboard

Product Demand Forecasting Dashboard

Total Forecasted Units

0

Total Forecasted Revenue

$0

Overall Forecast Accuracy

0%

Highest Demand Product

N/A

Demand Forecast vs. Actual Sales

Forecasted Revenue by Category

Demand Trend (Next 6 Months)

Forecast Accuracy by Product

Forecast Accuracy: ${accuracy.toFixed(1)}%

`; productDetailsContainer.classList.remove('hidden'); }; // --- IV. EVENT LISTENERS --- tabButtons.forEach((button, index) => button.addEventListener('click', () => showTab(index))); prevBtn.addEventListener('click', () => showTab(currentTabIndex - 1)); nextBtn.addEventListener('click', () => showTab(currentTabIndex + 1)); updateDataBtn.addEventListener('click', () => { try { const newData = JSON.parse(dataInput.value); if (Array.isArray(newData)) { currentForecastData = newData; jsonErrorMsg.classList.add('hidden'); updateDashboard(); alert('Dashboard updated successfully!'); showTab(0); } else { throw new Error("Data is not an array."); } } catch (error) { jsonErrorMsg.classList.remove('hidden'); } }); productSelect.addEventListener('change', showProductDetails); downloadPdfBtn.addEventListener('click', async () => { const dashboardArea = getElement('dashboard-export-area'); if (!dashboardArea) return; const originalButtonText = downloadPdfBtn.textContent; downloadPdfBtn.textContent = 'Generating PDF...'; downloadPdfBtn.disabled = true; try { const canvas = await html2canvas(dashboardArea, { scale: 2, useCORS: true, logging: false, width: dashboardArea.scrollWidth, height: dashboardArea.scrollHeight, windowWidth: dashboardArea.scrollWidth, windowHeight: dashboardArea.scrollHeight }); const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdfWidth = 297, pdfHeight = 210, margin = 15; const aspectRatio = canvas.width / canvas.height; let scaledWidth = pdfWidth - (margin * 2); let scaledHeight = scaledWidth / aspectRatio; if (scaledHeight > pdfHeight - (margin * 2)) { scaledHeight = pdfHeight - (margin * 2); scaledWidth = scaledHeight * aspectRatio; } const xOffset = (pdfWidth - scaledWidth) / 2; const yOffset = (pdfHeight - scaledHeight) / 2; const pdf = new jsPDF({ orientation: 'landscape', unit: 'mm', format: 'a4' }); pdf.addImage(imgData, 'PNG', xOffset, yOffset, scaledWidth, scaledHeight); pdf.save('Product_Demand_Forecast_Dashboard.pdf'); } catch (error) { console.error("PDF generation failed:", error); alert("Sorry, there was an error generating the PDF. Please try again."); } finally { downloadPdfBtn.textContent = originalButtonText; downloadPdfBtn.disabled = false; } }); // --- V. INITIALIZATION CALLS --- dataInput.value = JSON.stringify(initialForecastData, null, 4); updateDashboard(); showTab(0); });
Scroll to Top