const fullData = [ { x: new Date('2025-06-20'), y: 3381.30 }, { x: new Date('2025-06-22'), y: 3412.90 }, { x: new Date('2025-06-23'), y: 3412.90 }, { x: new Date('2025-06-24'), y: 3370.90 }, { x: new Date('2025-06-25'), y: 3325.50 }, { x: new Date('2025-06-26'), y: 3331.10 }, { x: new Date('2025-06-27'), y: 3326.70 }, { x: new Date('2025-06-28'), y: 3278.30 }, { x: new Date('2025-06-30'), y: 3272.30 }, { x: new Date('2025-07-01'), y: 3305.40 }, { x: new Date('2025-07-02'), y: 3336.10 }, { x: new Date('2025-07-03'), y: 3352.00 }]; const options = { chart: { type: 'area', height: 300, toolbar: { show: false }, zoom: { enabled: false } }, series: [{ name: '', data: fullData }], xaxis: { type: 'datetime' }, yaxis: { tickAmount: 7, labels: { formatter: val => `${val.toLocaleString('id-ID')}`, offsetX: -17 } }, grid: { padding: { left: -10, right: 0 } }, tooltip: { x: { format: 'dd MMM yyyy' }, y: { formatter: val => `US$${val.toLocaleString('id-ID')}` } }, stroke: { curve: 'smooth', width: 2 }, fill: { type: 'gradient', gradient: { shadeIntensity: 1, opacityFrom: 0.8, opacityTo: 0, stops: [0, 90, 100] } }, colors: ['#007bff'], legend: { show: false }, dataLabels: { enabled: false } }; const chart = new ApexCharts(document.querySelector("#chart"), options); chart.render(); function updateChart(months) { const sortedData = [...fullData].sort((a, b) => a.x - b.x); const latestDate = sortedData[sortedData.length - 1].x; const start = new Date(latestDate); start.setMonth(start.getMonth() - months); const filtered = fullData.filter(item => item.x >= start && item.x <= latestDate); chart.updateSeries([{ name: '', data: filtered }]); } document.querySelectorAll('.filter-btn').forEach(btn => { btn.addEventListener('click', () => { document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active')); btn.classList.add('active'); const months = parseInt(btn.dataset.months); updateChart(months); }); }); updateChart(1);