const fullData = [ { x: new Date('2024-02-02'), y: 106.80 }, { x: new Date('2024-02-05'), y: 105.97 }, { x: new Date('2024-02-06'), y: 105.92 }, { x: new Date('2024-02-07'), y: 105.98 }, { x: new Date('2024-02-08'), y: 105.72 }, { x: new Date('2024-02-09'), y: 104.93 }, { x: new Date('2024-02-10'), y: 104.56 }, { x: new Date('2024-02-12'), y: 104.63 }, { x: new Date('2024-02-13'), y: 104.24 }, { x: new Date('2024-02-14'), y: 104.00 }, { x: new Date('2024-05-20'), y: 102.54 }, { x: new Date('2024-08-01'), y: 108.30 }, { x: new Date('2024-08-02'), y: 108.74 }, { x: new Date('2024-08-05'), y: 111.42 }, { x: new Date('2024-08-06'), y: 111.35 }, { x: new Date('2024-08-07'), y: 109.70 }, { x: new Date('2024-08-28'), y: 107.28 }, { x: new Date('2024-08-29'), y: 106.50 }, { x: new Date('2024-08-30'), y: 106.97 }, { x: new Date('2024-09-02'), y: 106.39 }, { x: new Date('2024-09-03'), y: 105.95 }, { x: new Date('2024-09-04'), y: 106.45 }, { x: new Date('2024-09-05'), y: 107.24 }, { x: new Date('2024-09-05'), y: 107.37 }, { x: new Date('2024-09-06'), y: 107.44 }, { x: new Date('2024-09-07'), y: 108.63 }, { x: new Date('2024-09-08'), y: 108.63 }, { x: new Date('2024-09-09'), y: 108.13 }, { x: new Date('2024-09-10'), y: 107.63 }, { x: new Date('2024-09-19'), y: 107.16 }, { x: new Date('2024-09-20'), y: 105.96 }, { x: new Date('2024-09-23'), y: 105.06 }, { x: new Date('2024-09-24'), y: 105.76 }, { x: new Date('2024-09-25'), y: 105.23 }, { x: new Date('2024-09-26'), y: 105.16 }, { x: new Date('2024-09-27'), y: 103.81 }, { x: new Date('2024-10-01'), y: 105.62 }, { x: new Date('2024-10-02'), y: 105.81 }, { x: new Date('2024-10-03'), y: 105.11 }, { x: new Date('2024-10-04'), y: 105.77 }, { x: new Date('2024-10-05'), y: 105.40 }, { x: new Date('2024-10-07'), y: 105.58 }, { x: new Date('2024-10-08'), y: 106.32 }, { x: new Date('2024-10-10'), y: 105.45 }, { x: new Date('2024-10-11'), y: 105.39 }, { x: new Date('2024-10-12'), y: 104.40 }, { x: new Date('2024-10-14'), y: 104.28 }, { x: new Date('2024-10-15'), y: 104.06 }, { x: new Date('2024-10-16'), y: 104.31 }, { x: new Date('2024-10-17'), y: 104.02 }, { x: new Date('2024-10-18'), y: 103.32 }, { x: new Date('2024-10-19'), y: 103.45 }, { x: new Date('2024-10-20'), y: 103.45 }, { x: new Date('2024-10-21'), y: 103.45 }, { x: new Date('2024-10-22'), y: 103.17 }, { x: new Date('2024-10-23'), y: 103.08 }, { x: new Date('2024-10-24'), y: 102.53 }, { x: new Date('2024-10-25'), y: 102.93 }, { x: new Date('2024-10-26'), y: 103.17 }, { x: new Date('2024-10-27'), y: 103.17 }, { x: new Date('2024-10-28'), y: 102.06 }, { x: new Date('2024-10-29'), y: 102.76 }, { x: new Date('2024-10-30'), y: 102.81 }, { x: new Date('2024-10-31'), y: 102.25 }, { x: new Date('2024-11-01'), y: 103.56 }, { x: new Date('2024-11-02'), y: 103.57 }, { x: new Date('2024-11-03'), y: 103.57 }, { x: new Date('2024-11-04'), y: 103.57 }, { x: new Date('2024-11-05'), y: 103.60 }, { x: new Date('2024-11-06'), y: 103.66 }, { x: new Date('2024-11-07'), y: 102.58 }, { x: new Date('2024-11-08'), y: 101.72 }, { x: new Date('2024-11-09'), y: 102.51 }, { x: new Date('2024-11-10'), y: 102.51 }, { x: new Date('2024-11-11'), y: 102.45 }, { x: new Date('2024-11-12'), y: 102.69 }, { x: new Date('2024-11-13'), y: 102.28 }, { x: new Date('2024-11-14'), y: 101.51 }, { x: new Date('2024-11-15'), y: 102.10 }, { x: new Date('2024-11-16'), y: 103.02 }, { x: new Date('2024-11-17'), y: 103.02 }, { x: new Date('2024-11-18'), y: 102.47 }, { x: new Date('2024-11-19'), y: 102.71 }, { x: new Date('2024-11-21'), y: 102.67 }, { x: new Date('2024-11-22'), y: 103.35 }, { x: new Date('2024-11-23'), y: 102.96 }, { x: new Date('2024-11-24'), y: 102.96 }, { x: new Date('2024-11-26'), y: 103.13 }, { x: new Date('2024-11-27'), y: 104.40 }, { x: new Date('2024-11-28'), y: 104.71 }, { x: new Date('2024-11-29'), y: 105.54 }, { x: new Date('2024-12-01'), y: 105.74 }, { x: new Date('2024-12-02'), y: 105.54 }, { x: new Date('2024-12-03'), y: 106.21 }, { x: new Date('2024-12-04'), y: 106.25 }, { x: new Date('2024-12-06'), y: 105.71 }, { x: new Date('2024-12-07'), y: 105.76 }, { x: new Date('2024-12-08'), y: 105.76 }, { x: new Date('2024-12-09'), y: 105.76 }, { x: new Date('2024-12-10'), y: 104.77 }, { x: new Date('2024-12-11'), y: 104.80 }, { x: new Date('2024-12-12'), y: 104.81 }, { x: new Date('2024-12-13'), y: 104.35 }, { x: new Date('2024-12-14'), y: 104.24 }, { x: new Date('2024-12-15'), y: 104.24 }, { x: new Date('2024-12-16'), y: 104.22 }, { x: new Date('2024-12-17'), y: 103.99 }, { x: new Date('2024-12-18'), y: 104.62 }, { x: new Date('2024-12-19'), y: 104.86 }, { x: new Date('2024-12-20'), y: 103.48 }, { x: new Date('2024-12-22'), y: 103.42 }, { x: new Date('2024-12-23'), y: 103.42 }, { x: new Date('2024-12-24'), y: 103.25 }, { x: new Date('2024-12-25'), y: 103.18 }, { x: new Date('2024-12-27'), y: 102.77 }, { x: new Date('2024-12-30'), y: 102.81 }, { x: new Date('2024-12-31'), y: 103.14 }, { x: new Date('2025-01-02'), y: 103.20 }, { x: new Date('2025-01-03'), y: 103.22 }, { x: new Date('2025-01-04'), y: 103.02 }, { x: new Date('2025-01-06'), y: 103.02 }, { x: new Date('2025-01-15'), y: 103.22 }, { x: new Date('2025-01-16'), y: 105.31 }, { x: new Date('2025-01-17'), y: 105.62 }, { x: new Date('2025-01-19'), y: 104.82 }, { x: new Date('2025-01-20'), y: 104.82 }, { x: new Date('2025-01-21'), y: 105.14 }, { x: new Date('2025-01-22'), y: 105.00 }, { x: new Date('2025-01-23'), y: 104.10 }, { x: new Date('2025-01-24'), y: 103.96 }, { x: new Date('2025-01-25'), y: 103.66 }, { x: new Date('2025-01-26'), y: 103.66 }, { x: new Date('2025-01-27'), y: 103.96 }, { x: new Date('2025-01-28'), y: 104.21 }, { x: new Date('2025-01-29'), y: 104.17 }, { x: new Date('2025-01-31'), y: 105.58 }, { x: new Date('2025-02-01'), y: 105.39 }, { x: new Date('2025-02-03'), y: 105.16 }, { x: new Date('2025-02-04'), y: 105.13 }, { x: new Date('2025-02-06'), y: 106.63 }, { x: new Date('2025-02-07'), y: 107.12 }, { x: new Date('2025-02-08'), y: 107.31 }, { x: new Date('2025-02-09'), y: 107.31 }, { x: new Date('2025-02-10'), y: 107.28 }, { x: new Date('2025-02-11'), y: 107.28 }, { x: new Date('2025-02-12'), y: 107.30 }, { x: new Date('2025-02-13'), y: 106.33 }, { x: new Date('2025-02-14'), y: 106.68 }, { x: new Date('2025-02-17'), y: 106.60 }, { x: new Date('2025-02-18'), y: 107.09 }, { x: new Date('2025-02-19'), y: 107.25 }, { x: new Date('2025-02-20'), y: 107.83 }, { x: new Date('2025-02-24'), y: 108.65 }, { x: new Date('2025-02-25'), y: 108.69 }, { x: new Date('2025-02-26'), y: 109.43 }, { x: new Date('2025-02-27'), y: 109.38 }, { x: new Date('2025-02-28'), y: 109.67 }, { x: new Date('2025-03-01'), y: 110.11 }, { x: new Date('2025-03-02'), y: 110.11 }, { x: new Date('2025-03-03'), y: 109.98 }, { x: new Date('2025-03-04'), y: 108.98 }, { x: new Date('2025-03-06'), y: 109.50 }, { x: new Date('2025-03-07'), y: 110.38 }, { x: new Date('2025-03-08'), y: 110.34 }, { x: new Date('2025-03-10'), y: 110.37 }, { x: new Date('2025-03-11'), y: 111.29 }, { x: new Date('2025-03-12'), y: 111.09 }, { x: new Date('2025-03-13'), y: 110.56 }, { x: new Date('2025-03-14'), y: 110.87 }, { x: new Date('2025-03-15'), y: 109.99 }, { x: new Date('2025-03-16'), y: 109.95 }, { x: new Date('2025-03-17'), y: 109.95 }, { x: new Date('2025-03-18'), y: 110.07 }, { x: new Date('2025-03-19'), y: 110.05 }, { x: new Date('2025-03-20'), y: 110.51 }, { x: new Date('2025-03-21'), y: 110.91 }, { x: new Date('2025-03-22'), y: 110.69 }, { x: new Date('2025-03-23'), y: 110.68 }, { x: new Date('2025-03-24'), y: 110.46 }, { x: new Date('2025-03-25'), y: 110.46 }, { x: new Date('2025-03-26'), y: 110.67 }, { x: new Date('2025-03-27'), y: 110.34 }, { x: new Date('2025-03-28'), y: 109.93 }, { x: new Date('2025-03-30'), y: 110.43 }, { x: new Date('2025-03-31'), y: 110.75 }, { x: new Date('2025-04-01'), y: 110.65 }, { x: new Date('2025-04-02'), y: 110.83 }, { x: new Date('2025-04-03'), y: 111.44 }, { x: new Date('2025-04-04'), y: 113.47 }, { x: new Date('2025-04-05'), y: 112.93 }, { x: new Date('2025-04-06'), y: 112.97 }, { x: new Date('2025-04-07'), y: 113.35 }, { x: new Date('2025-04-08'), y: 112.11 }, { x: new Date('2025-04-09'), y: 115.45 }, { x: new Date('2025-04-10'), y: 115.59 }, { x: new Date('2025-04-11'), y: 116.03 }, { x: new Date('2025-04-12'), y: 116.96 }, { x: new Date('2025-04-13'), y: 117.10 }, { x: new Date('2025-04-14'), y: 116.99 }, { x: new Date('2025-04-15'), y: 117.08 }, { x: new Date('2025-04-16'), y: 117.57 }, { x: new Date('2025-04-17'), y: 118.02 }, { x: new Date('2025-04-18'), y: 118.32 }, { x: new Date('2025-04-19'), y: 118.34 }, { x: new Date('2025-04-20'), y: 118.34 }, { x: new Date('2025-04-21'), y: 118.76 }, { x: new Date('2025-04-22'), y: 119.53 }, { x: new Date('2025-04-23'), y: 119.94 }, { x: new Date('2025-04-24'), y: 118.46 }, { x: new Date('2025-04-26'), y: 117.47 }, { x: new Date('2025-04-27'), y: 117.47 }, { x: new Date('2025-04-28'), y: 117.22 }, { x: new Date('2025-05-02'), y: 114.71 }, { x: new Date('2025-05-05'), y: 113.65 }, { x: new Date('2025-05-06'), y: 113.65 }, { x: new Date('2025-05-08'), y: 115.00 }, { x: new Date('2025-05-09'), y: 113.66 }, { x: new Date('2025-05-10'), y: 113.92 }, { x: new Date('2025-05-11'), y: 113.88 }, { x: new Date('2025-05-12'), y: 113.49 }, { x: new Date('2025-05-13'), y: 111.34 }, { x: new Date('2025-05-14'), y: 111.80 }, { x: new Date('2025-05-15'), y: 113.16 }, { x: new Date('2025-05-16'), y: 113.21 }, { x: new Date('2025-05-17'), y: 112.84 }, { x: new Date('2025-05-19'), y: 113.10 }, { x: new Date('2025-05-20'), y: 113.43 }, { x: new Date('2025-05-21'), y: 113.53 }, { x: new Date('2025-05-22'), y: 114.07 }, { x: new Date('2025-05-24'), y: 113.50 }, { x: new Date('2025-05-26'), y: 113.45 }, { x: new Date('2025-05-27'), y: 113.36 }, { x: new Date('2025-06-04'), y: 113.59 }, { x: new Date('2025-06-05'), y: 113.71 }, { x: new Date('2025-06-06'), y: 113.39 }, { x: new Date('2025-06-07'), y: 112.63 }, { x: new Date('2025-06-08'), y: 112.71 }, { x: new Date('2025-06-10'), y: 112.70 }, { x: new Date('2025-06-11'), y: 112.43 }, { x: new Date('2025-06-12'), y: 112.42 }, { x: new Date('2025-06-13'), y: 112.99 }, { x: new Date('2025-06-14'), y: 113.43 }, { x: new Date('2025-06-15'), y: 113.38 }, { x: new Date('2025-06-16'), y: 112.89 }, { x: new Date('2025-06-17'), y: 112.82 }, { x: new Date('2025-06-18'), y: 111.91 }, { x: new Date('2025-06-20'), y: 112.53 }, { x: new Date('2025-06-21'), y: 112.36 }, { x: new Date('2025-06-22'), y: 112.39 }, { x: new Date('2025-06-23'), y: 112.22 }, { x: new Date('2025-06-24'), y: 112.57 }, { x: new Date('2025-06-25'), y: 112.75 }, { x: new Date('2025-06-26'), y: 112.20 }, { x: new Date('2025-06-27'), y: 112.38 }, { x: new Date('2025-06-28'), y: 112.21 }, { x: new Date('2025-06-29'), y: 112.19 }, { x: new Date('2025-06-30'), y: 112.17 }, { x: new Date('2025-07-01'), y: 112.64 }, { x: new Date('2025-07-02'), y: 113.12 }, { x: new Date('2025-07-04'), y: 111.96 }, { x: new Date('2025-07-05'), y: 112.07 }, { x: new Date('2025-07-06'), y: 112.07 }, { x: new Date('2025-07-07'), y: 112.02 }, { x: new Date('2025-07-08'), y: 111.41 }, { x: new Date('2025-07-09'), y: 110.79 }, { x: new Date('2025-07-10'), y: 111.05 }, { x: new Date('2025-07-12'), y: 110.27 }, { x: new Date('2025-07-13'), y: 110.24 }, { x: new Date('2025-07-14'), y: 110.29 }, { x: new Date('2025-07-16'), y: 109.69 }, { x: new Date('2025-07-17'), y: 109.86 }, { x: new Date('2025-07-19'), y: 109.72 }, { x: new Date('2025-07-20'), y: 109.71 }, { x: new Date('2025-07-21'), y: 109.75 }, { x: new Date('2025-07-22'), y: 110.60 }, { x: new Date('2025-07-23'), y: 110.83 }, { x: new Date('2025-07-24'), y: 111.08 }, { x: new Date('2025-07-25'), y: 110.90 }, { x: new Date('2025-07-26'), y: 110.49 }, { x: new Date('2025-07-27'), y: 110.48 }, { x: new Date('2025-07-29'), y: 110.18 }, { x: new Date('2025-07-30'), y: 110.37 }, { x: new Date('2025-07-31'), y: 110.29 }, { x: new Date('2025-08-01'), y: 109.62 }, { x: new Date('2025-08-02'), y: 110.19 }, { x: new Date('2025-08-03'), y: 109.94 }, { x: new Date('2025-08-04'), y: 109.18 }, { x: new Date('2025-08-05'), y: 111.30 }, { x: new Date('2025-08-06'), y: 111.05 }, { x: new Date('2025-08-07'), y: 110.99 }, { x: new Date('2025-08-08'), y: 110.89 }, { x: new Date('2025-08-09'), y: 110.45 }, { x: new Date('2025-08-10'), y: 110.38 }, { x: new Date('2025-08-11'), y: 110.22 }, { x: new Date('2025-08-12'), y: 109.75 }, { x: new Date('2025-08-13'), y: 109.84 }, { x: new Date('2025-08-14'), y: 109.86 }, { x: new Date('2025-08-15'), y: 109.24 }, { x: new Date('2025-08-16'), y: 109.70 }, { x: new Date('2025-08-18'), y: 109.86 }, { x: new Date('2025-08-19'), y: 109.57 }, { x: new Date('2025-08-20'), y: 110.08 }, { x: new Date('2025-08-21'), y: 110.51 }, { x: new Date('2025-08-22'), y: 110.18 }, { x: new Date('2025-08-23'), y: 110.34 }, { x: new Date('2025-08-24'), y: 110.20 }, { x: new Date('2025-08-25'), y: 109.95 }, { x: new Date('2025-08-26'), y: 110.20 }, { x: new Date('2025-08-27'), y: 110.55 }, { x: new Date('2025-08-28'), y: 111.10 }, { x: new Date('2025-08-29'), y: 111.26 }, { x: new Date('2025-08-30'), y: 112.27 }, { x: new Date('2025-08-31'), y: 112.19 }]; 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);