const fullData = [ { x: new Date('2025-04-09'), y: 1686.59 }, { x: new Date('2025-04-10'), y: 1688.02 }, { x: new Date('2025-04-11'), y: 1701.62 }, { x: new Date('2025-04-12'), y: 1705.97 }, { x: new Date('2025-04-13'), y: 1707.46 }, { x: new Date('2025-04-14'), y: 1717.71 }, { x: new Date('2025-04-15'), y: 1722.53 }, { x: new Date('2025-04-16'), y: 1711.30 }, { x: new Date('2025-04-17'), y: 1716.87 }, { x: new Date('2025-04-18'), y: 1740.95 }, { x: new Date('2025-04-19'), y: 1747.13 }, { x: new Date('2025-04-20'), y: 1746.47 }, { x: new Date('2025-04-21'), y: 1758.27 }, { x: new Date('2025-04-22'), y: 1766.05 }, { x: new Date('2025-04-23'), y: 1762.66 }, { x: new Date('2025-04-24'), y: 1751.71 }, { x: new Date('2025-04-26'), y: 1742.37 }, { x: new Date('2025-04-27'), y: 1742.04 }, { x: new Date('2025-04-28'), y: 1735.96 }, { x: new Date('2025-05-02'), y: 1709.27 }, { x: new Date('2025-05-05'), y: 1705.22 }, { x: new Date('2025-05-06'), y: 1705.22 }, { x: new Date('2025-05-08'), y: 1713.16 }, { x: new Date('2025-05-09'), y: 1703.22 }, { x: new Date('2025-05-10'), y: 1706.56 }, { x: new Date('2025-05-11'), y: 1706.13 }, { x: new Date('2025-05-12'), y: 1701.39 }, { x: new Date('2025-05-13'), y: 1681.33 }, { x: new Date('2025-05-14'), y: 1697.46 }, { x: new Date('2025-05-15'), y: 1705.79 }, { x: new Date('2025-05-16'), y: 1694.44 }, { x: new Date('2025-05-17'), y: 1682.32 }, { x: new Date('2025-05-19'), y: 1687.51 }, { x: new Date('2025-05-20'), y: 1696.41 }, { x: new Date('2025-05-21'), y: 1698.95 }, { x: new Date('2025-05-22'), y: 1713.54 }, { x: new Date('2025-05-24'), y: 1699.34 }, { x: new Date('2025-05-26'), y: 1695.38 }, { x: new Date('2025-05-27'), y: 1703.18 }, { x: new Date('2025-06-04'), y: 1697.46 }, { x: new Date('2025-06-05'), y: 1698.78 }, { x: new Date('2025-06-06'), y: 1700.31 }, { x: new Date('2025-06-07'), y: 1696.23 }, { x: new Date('2025-06-08'), y: 1696.65 }, { x: new Date('2025-06-10'), y: 1695.64 }, { x: new Date('2025-06-11'), y: 1697.21 }, { x: new Date('2025-06-12'), y: 1699.63 }, { x: new Date('2025-06-13'), y: 1717.42 }, { x: new Date('2025-06-14'), y: 1718.35 }, { x: new Date('2025-06-15'), y: 1717.29 }, { x: new Date('2025-06-16'), y: 1715.65 }, { x: new Date('2025-06-17'), y: 1720.06 }, { x: new Date('2025-06-18'), y: 1707.04 }, { x: new Date('2025-06-20'), y: 1699.54 }, { x: new Date('2025-06-21'), y: 1696.07 }, { x: new Date('2025-06-22'), y: 1696.13 }, { x: new Date('2025-06-23'), y: 1691.89 }, { x: new Date('2025-06-24'), y: 1701.25 }, { x: new Date('2025-06-25'), y: 1713.86 }, { x: new Date('2025-06-26'), y: 1716.65 }, { x: new Date('2025-06-27'), y: 1710.50 }, { x: new Date('2025-06-28'), y: 1711.86 }, { x: new Date('2025-06-29'), y: 1711.47 }, { x: new Date('2025-06-30'), y: 1711.78 }, { x: new Date('2025-07-01'), y: 1711.07 }, { x: new Date('2025-07-02'), y: 1711.87 }, { x: new Date('2025-07-04'), y: 1690.93 }, { x: new Date('2025-07-05'), y: 1693.96 }, { x: new Date('2025-07-06'), y: 1694.06 }, { x: new Date('2025-07-07'), y: 1693.57 }, { x: new Date('2025-07-08'), y: 1706.91 }, { x: new Date('2025-07-09'), y: 1705.67 }, { x: new Date('2025-07-10'), y: 1707.66 }, { x: new Date('2025-07-12'), y: 1701.49 }, { x: new Date('2025-07-13'), y: 1700.89 }, { x: new Date('2025-07-14'), y: 1700.90 }, { x: new Date('2025-07-16'), y: 1678.28 }, { x: new Date('2025-07-17'), y: 1674.32 }, { x: new Date('2025-07-19'), y: 1687.35 }, { x: new Date('2025-07-20'), y: 1686.61 }, { x: new Date('2025-07-21'), y: 1686.73 }, { x: new Date('2025-07-22'), y: 1699.68 }, { x: new Date('2025-07-23'), y: 1705.93 }, { x: new Date('2025-07-24'), y: 1709.88 }, { x: new Date('2025-07-25'), y: 1709.11 }, { x: new Date('2025-07-26'), y: 1712.72 }, { x: new Date('2025-07-27'), y: 1712.88 }, { x: new Date('2025-07-29'), y: 1705.22 }, { x: new Date('2025-07-30'), y: 1698.09 }, { x: new Date('2025-07-31'), y: 1685.17 }, { x: new Date('2025-08-01'), y: 1686.72 }, { x: new Date('2025-08-02'), y: 1692.84 }, { x: new Date('2025-08-03'), y: 1690.46 }, { x: new Date('2025-08-04'), y: 1699.42 }, { x: new Date('2025-08-05'), y: 1694.95 }, { x: new Date('2025-08-06'), y: 1694.25 }, { x: new Date('2025-08-07'), y: 1699.07 }, { x: new Date('2025-08-08'), y: 1702.59 }, { x: new Date('2025-08-09'), y: 1702.39 }, { x: new Date('2025-08-10'), y: 1700.56 }, { x: new Date('2025-08-11'), y: 1698.24 }, { x: new Date('2025-08-12'), y: 1687.46 }, { x: new Date('2025-08-13'), y: 1696.16 }, { x: new Date('2025-08-14'), y: 1696.64 }, { x: new Date('2025-08-15'), y: 1682.05 }, { x: new Date('2025-08-16'), y: 1684.64 }, { x: new Date('2025-08-18'), y: 1690.96 }, { x: new Date('2025-08-19'), y: 1691.11 }, { x: new Date('2025-08-20'), y: 1698.60 }, { x: new Date('2025-08-21'), y: 1697.58 }, { x: new Date('2025-08-22'), y: 1698.11 }, { x: new Date('2025-08-23'), y: 1708.53 }, { x: new Date('2025-08-24'), y: 1706.22 }, { x: new Date('2025-08-25'), y: 1698.93 }, { x: new Date('2025-08-26'), y: 1702.43 }, { x: new Date('2025-08-27'), y: 1702.91 }, { x: new Date('2025-08-28'), y: 1715.52 }, { x: new Date('2025-08-29'), y: 1723.99 }, { x: new Date('2025-08-30'), y: 1742.62 }, { x: new Date('2025-08-31'), y: 1741.31 }]; 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 => `Rp ${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);