Economic Indicator Analyzer

Economic Indicator Analyzer

Simulated analysis of key economic trends.

Analysis Configuration

Analysis results will be displayed here.

Historical Trend & Forecast

Indicator Chart

AI-Generated Analysis

${aiAnalysis}

`; updateChart(); } function updateChart() { const { labels, data, forecast } = analysisData.simulatedData; const ctx = document.getElementById('indicator-chart').getContext('2d'); if (indicatorChart) indicatorChart.destroy(); indicatorChart = new Chart(ctx, { type: 'line', data: { labels, datasets: [{ label: 'Historical', data: data, borderColor: '#4b5563', tension: 0.1 }, { label: 'Forecast', data: new Array(data.length).fill(null).concat(forecast), borderColor: '#ef4444', borderDash: [5, 5], tension: 0.1 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } } }); } async function handlePdfDownload() { // Populate PDF data document.getElementById('pdf-header').innerHTML = `

Economic Analysis: ${analysisData.indicator}

Country: ${analysisData.country} | Generated: ${new Date().toLocaleString()}

`; document.getElementById('pdf-summary-grid').innerHTML = `

Current Value

${document.getElementById('current-value').textContent}

5-Year High

${document.getElementById('high-value').textContent}

5-Year Low

${document.getElementById('low-value').textContent}

`; document.getElementById('pdf-chart-img').src = indicatorChart ? indicatorChart.toBase64Image() : ''; document.getElementById('pdf-analysis-text').textContent = analysisData.aiAnalysis; const contentToPrint = document.getElementById('pdf-output'); contentToPrint.style.display = 'block'; try { const canvas = await html2canvas(contentToPrint, { scale: 2 }); const { jsPDF } = window.jspdf; const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save(`Economic-Analysis-${analysisData.indicator.replace(/ /g, '_')}.pdf`); } catch (err) { console.error("Error generating PDF:", err); alert("Could not generate PDF."); } finally { contentToPrint.style.display = 'none'; } } // --- EVENT LISTENERS --- analyzeBtn.addEventListener('click', handleAnalysis); downloadPdfBtn.addEventListener('click', handlePdfDownload); // --- INITIALIZATION --- lucide.createIcons(); });
Scroll to Top