const fullData = [ { x: new Date('2025-04-09'), y: 1545.80 }, { x: new Date('2025-04-10'), y: 1550.94 }, { x: new Date('2025-04-11'), y: 1557.51 }, { x: new Date('2025-04-12'), y: 1567.11 }, { x: new Date('2025-04-13'), y: 1568.99 }, { x: new Date('2025-04-14'), y: 1572.05 }, { x: new Date('2025-04-15'), y: 1585.82 }, { x: new Date('2025-04-16'), y: 1585.07 }, { x: new Date('2025-04-17'), y: 1584.85 }, { x: new Date('2025-04-18'), y: 1603.65 }, { x: new Date('2025-04-19'), y: 1604.88 }, { x: new Date('2025-04-20'), y: 1604.89 }, { x: new Date('2025-04-21'), y: 1610.23 }, { x: new Date('2025-04-22'), y: 1619.94 }, { x: new Date('2025-04-23'), y: 1623.15 }, { x: new Date('2025-04-24'), y: 1613.13 }, { x: new Date('2025-04-26'), y: 1615.97 }, { x: new Date('2025-04-27'), y: 1616.28 }, { x: new Date('2025-04-28'), y: 1614.79 }, { x: new Date('2025-05-02'), y: 1594.74 }, { x: new Date('2025-05-05'), y: 1585.39 }, { x: new Date('2025-05-06'), y: 1585.39 }, { x: new Date('2025-05-08'), y: 1594.67 }, { x: new Date('2025-05-09'), y: 1588.56 }, { x: new Date('2025-05-10'), y: 1596.77 }, { x: new Date('2025-05-11'), y: 1595.59 }, { x: new Date('2025-05-12'), y: 1592.86 }, { x: new Date('2025-05-13'), y: 1583.30 }, { x: new Date('2025-05-14'), y: 1591.52 }, { x: new Date('2025-05-15'), y: 1601.02 }, { x: new Date('2025-05-16'), y: 1584.12 }, { x: new Date('2025-05-17'), y: 1581.48 }, { x: new Date('2025-05-19'), y: 1584.38 }, { x: new Date('2025-05-20'), y: 1594.30 }, { x: new Date('2025-05-21'), y: 1596.33 }, { x: new Date('2025-05-22'), y: 1614.83 }, { x: new Date('2025-05-24'), y: 1600.25 }, { x: new Date('2025-05-26'), y: 1596.55 }, { x: new Date('2025-05-27'), y: 1605.03 }, { x: new Date('2025-06-04'), y: 1609.14 }, { x: new Date('2025-06-05'), y: 1612.23 }, { x: new Date('2025-06-06'), y: 1615.22 }, { x: new Date('2025-06-07'), y: 1614.64 }, { x: new Date('2025-06-08'), y: 1614.55 }, { x: new Date('2025-06-10'), y: 1617.21 }, { x: new Date('2025-06-11'), y: 1612.68 }, { x: new Date('2025-06-12'), y: 1613.51 }, { x: new Date('2025-06-13'), y: 1628.73 }, { x: new Date('2025-06-14'), y: 1644.77 }, { x: new Date('2025-06-15'), y: 1643.17 }, { x: new Date('2025-06-16'), y: 1641.83 }, { x: new Date('2025-06-17'), y: 1645.00 }, { x: new Date('2025-06-18'), y: 1637.59 }, { x: new Date('2025-06-20'), y: 1631.41 }, { x: new Date('2025-06-21'), y: 1623.41 }, { x: new Date('2025-06-22'), y: 1623.60 }, { x: new Date('2025-06-23'), y: 1622.89 }, { x: new Date('2025-06-24'), y: 1632.79 }, { x: new Date('2025-06-25'), y: 1616.23 }, { x: new Date('2025-06-26'), y: 1609.48 }, { x: new Date('2025-06-27'), y: 1609.08 }, { x: new Date('2025-06-28'), y: 1611.26 }, { x: new Date('2025-06-29'), y: 1611.10 }, { x: new Date('2025-06-30'), y: 1610.66 }, { x: new Date('2025-07-01'), y: 1609.46 }, { x: new Date('2025-07-02'), y: 1611.52 }, { x: new Date('2025-07-04'), y: 1607.22 }, { x: new Date('2025-07-05'), y: 1607.82 }, { x: new Date('2025-07-06'), y: 1607.63 }, { x: new Date('2025-07-07'), y: 1609.23 }, { x: new Date('2025-07-08'), y: 1605.39 }, { x: new Date('2025-07-09'), y: 1609.28 }, { x: new Date('2025-07-10'), y: 1610.34 }, { x: new Date('2025-07-12'), y: 1603.21 }, { x: new Date('2025-07-13'), y: 1602.20 }, { x: new Date('2025-07-14'), y: 1602.98 }, { x: new Date('2025-07-16'), y: 1592.35 }, { x: new Date('2025-07-17'), y: 1586.53 }, { x: new Date('2025-07-19'), y: 1603.09 }, { x: new Date('2025-07-20'), y: 1601.56 }, { x: new Date('2025-07-21'), y: 1601.63 }, { x: new Date('2025-07-22'), y: 1603.86 }, { x: new Date('2025-07-23'), y: 1609.73 }, { x: new Date('2025-07-24'), y: 1610.48 }, { x: new Date('2025-07-25'), y: 1609.84 }, { x: new Date('2025-07-26'), y: 1606.55 }, { x: new Date('2025-07-27'), y: 1606.84 }, { x: new Date('2025-07-29'), y: 1605.04 }, { x: new Date('2025-07-30'), y: 1604.73 }, { x: new Date('2025-07-31'), y: 1599.81 }, { x: new Date('2025-08-01'), y: 1598.15 }, { x: new Date('2025-08-02'), y: 1600.20 }, { x: new Date('2025-08-03'), y: 1598.95 }, { x: new Date('2025-08-04'), y: 1603.00 }, { x: new Date('2025-08-05'), y: 1596.07 }, { x: new Date('2025-08-06'), y: 1596.99 }, { x: new Date('2025-08-07'), y: 1604.08 }, { x: new Date('2025-08-08'), y: 1596.98 }, { x: new Date('2025-08-09'), y: 1588.39 }, { x: new Date('2025-08-10'), y: 1587.88 }, { x: new Date('2025-08-11'), y: 1584.99 }, { x: new Date('2025-08-12'), y: 1588.29 }, { x: new Date('2025-08-13'), y: 1589.97 }, { x: new Date('2025-08-14'), y: 1584.93 }, { x: new Date('2025-08-15'), y: 1575.30 }, { x: new Date('2025-08-16'), y: 1581.36 }, { x: new Date('2025-08-18'), y: 1589.07 }, { x: new Date('2025-08-19'), y: 1587.28 }, { x: new Date('2025-08-20'), y: 1585.28 }, { x: new Date('2025-08-21'), y: 1589.24 }, { x: new Date('2025-08-22'), y: 1602.33 }, { x: new Date('2025-08-23'), y: 1614.17 }, { x: new Date('2025-08-24'), y: 1611.76 }, { x: new Date('2025-08-25'), y: 1603.93 }, { x: new Date('2025-08-26'), y: 1608.21 }, { x: new Date('2025-08-27'), y: 1606.82 }, { x: new Date('2025-08-28'), y: 1620.22 }, { x: new Date('2025-08-29'), y: 1624.26 }, { x: new Date('2025-08-30'), y: 1640.76 }, { x: new Date('2025-08-31'), y: 1639.45 }]; 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);