const fullData = [ { x: new Date('2024-02-02'), y: 15684 }, { x: new Date('2024-02-05'), y: 15731 }, { x: new Date('2024-02-06'), y: 15741 }, { x: new Date('2024-02-07'), y: 15682 }, { x: new Date('2024-02-08'), y: 15651 }, { x: new Date('2024-02-09'), y: 15665 }, { x: new Date('2024-02-10'), y: 15611 }, { x: new Date('2024-02-12'), y: 15611 }, { x: new Date('2024-02-13'), y: 15578 }, { x: new Date('2024-02-14'), y: 15661 }, { x: new Date('2024-05-20'), y: 15975 }, { x: new Date('2024-08-01'), y: 16237 }, { x: new Date('2024-08-02'), y: 16251 }, { x: new Date('2024-08-05'), y: 16169 }, { x: new Date('2024-08-06'), y: 16188 }, { x: new Date('2024-08-07'), y: 16037 }, { x: new Date('2024-08-28'), y: 15494 }, { x: new Date('2024-08-29'), y: 15399 }, { x: new Date('2024-08-30'), y: 15488 }, { x: new Date('2024-09-02'), y: 15530 }, { x: new Date('2024-09-03'), y: 15573 }, { x: new Date('2024-09-04'), y: 15477 }, { x: new Date('2024-09-05'), y: 15406 }, { x: new Date('2024-09-05'), y: 15413 }, { x: new Date('2024-09-06'), y: 15360 }, { x: new Date('2024-09-07'), y: 15458 }, { x: new Date('2024-09-08'), y: 15458 }, { x: new Date('2024-09-09'), y: 15433 }, { x: new Date('2024-09-10'), y: 15437 }, { x: new Date('2024-09-19'), y: 15362 }, { x: new Date('2024-09-20'), y: 15096 }, { x: new Date('2024-09-23'), y: 15161 }, { x: new Date('2024-09-24'), y: 15190 }, { x: new Date('2024-09-25'), y: 15082 }, { x: new Date('2024-09-26'), y: 15199 }, { x: new Date('2024-09-27'), y: 15155 }, { x: new Date('2024-10-01'), y: 15197 }, { x: new Date('2024-10-02'), y: 15224 }, { x: new Date('2024-10-03'), y: 15410 }, { x: new Date('2024-10-04'), y: 15485 }, { x: new Date('2024-10-05'), y: 15670 }, { x: new Date('2024-10-07'), y: 15670 }, { x: new Date('2024-10-08'), y: 15711 }, { x: new Date('2024-10-10'), y: 15707 }, { x: new Date('2024-10-11'), y: 15665 }, { x: new Date('2024-10-12'), y: 15569 }, { x: new Date('2024-10-14'), y: 15569 }, { x: new Date('2024-10-15'), y: 15577 }, { x: new Date('2024-10-16'), y: 15564 }, { x: new Date('2024-10-17'), y: 15568 }, { x: new Date('2024-10-18'), y: 15525 }, { x: new Date('2024-10-19'), y: 15474 }, { x: new Date('2024-10-20'), y: 15474 }, { x: new Date('2024-10-21'), y: 15474 }, { x: new Date('2024-10-22'), y: 15558 }, { x: new Date('2024-10-23'), y: 15593 }, { x: new Date('2024-10-24'), y: 15647 }, { x: new Date('2024-10-25'), y: 15636 }, { x: new Date('2024-10-26'), y: 15695 }, { x: new Date('2024-10-27'), y: 15695 }, { x: new Date('2024-10-28'), y: 15640 }, { x: new Date('2024-10-29'), y: 15753 }, { x: new Date('2024-10-30'), y: 15751 }, { x: new Date('2024-10-31'), y: 15689 }, { x: new Date('2024-11-01'), y: 15723 }, { x: new Date('2024-11-02'), y: 15849 }, { x: new Date('2024-11-03'), y: 15849 }, { x: new Date('2024-11-04'), y: 15849 }, { x: new Date('2024-11-05'), y: 15794 }, { x: new Date('2024-11-06'), y: 15717 }, { x: new Date('2024-11-07'), y: 15829 }, { x: new Date('2024-11-08'), y: 15574 }, { x: new Date('2024-11-09'), y: 15654 }, { x: new Date('2024-11-10'), y: 15654 }, { x: new Date('2024-11-11'), y: 15670 }, { x: new Date('2024-11-12'), y: 15771 }, { x: new Date('2024-11-13'), y: 15826 }, { x: new Date('2024-11-14'), y: 15817 }, { x: new Date('2024-11-15'), y: 15976 }, { x: new Date('2024-11-16'), y: 15898 }, { x: new Date('2024-11-17'), y: 15898 }, { x: new Date('2024-11-18'), y: 15855 }, { x: new Date('2024-11-19'), y: 15852 }, { x: new Date('2024-11-21'), y: 15918 }, { x: new Date('2024-11-22'), y: 15922 }, { x: new Date('2024-11-23'), y: 15943 }, { x: new Date('2024-11-24'), y: 15943 }, { x: new Date('2024-11-26'), y: 15880 }, { x: new Date('2024-11-27'), y: 15923 }, { x: new Date('2024-11-28'), y: 15855 }, { x: new Date('2024-11-29'), y: 15849 }, { x: new Date('2024-12-01'), y: 15836 }, { x: new Date('2024-12-02'), y: 15836 }, { x: new Date('2024-12-03'), y: 15946 }, { x: new Date('2024-12-04'), y: 15947 }, { x: new Date('2024-12-06'), y: 15845 }, { x: new Date('2024-12-07'), y: 15865 }, { x: new Date('2024-12-08'), y: 15865 }, { x: new Date('2024-12-09'), y: 15865 }, { x: new Date('2024-12-10'), y: 15854 }, { x: new Date('2024-12-11'), y: 15914 }, { x: new Date('2024-12-12'), y: 15950 }, { x: new Date('2024-12-13'), y: 15951 }, { x: new Date('2024-12-14'), y: 16032 }, { x: new Date('2024-12-15'), y: 16032 }, { x: new Date('2024-12-16'), y: 16032 }, { x: new Date('2024-12-17'), y: 16035 }, { x: new Date('2024-12-18'), y: 16084 }, { x: new Date('2024-12-19'), y: 16274 }, { x: new Date('2024-12-20'), y: 16326 }, { x: new Date('2024-12-22'), y: 16171 }, { x: new Date('2024-12-23'), y: 16171 }, { x: new Date('2024-12-24'), y: 16236 }, { x: new Date('2024-12-25'), y: 16214 }, { x: new Date('2024-12-27'), y: 16226 }, { x: new Date('2024-12-30'), y: 16235 }, { x: new Date('2024-12-31'), y: 16144 }, { x: new Date('2025-01-02'), y: 16239 }, { x: new Date('2025-01-03'), y: 16241 }, { x: new Date('2025-01-04'), y: 16200 }, { x: new Date('2025-01-06'), y: 16200 }, { x: new Date('2025-01-15'), y: 16299 }, { x: new Date('2025-01-16'), y: 16381 }, { x: new Date('2025-01-17'), y: 16417 }, { x: new Date('2025-01-19'), y: 16380 }, { x: new Date('2025-01-20'), y: 16365 }, { x: new Date('2025-01-21'), y: 16303 }, { x: new Date('2025-01-22'), y: 16321 }, { x: new Date('2025-01-23'), y: 16275 }, { x: new Date('2025-01-24'), y: 16238 }, { x: new Date('2025-01-25'), y: 16170 }, { x: new Date('2025-01-26'), y: 16170 }, { x: new Date('2025-01-27'), y: 16170 }, { x: new Date('2025-01-28'), y: 16216 }, { x: new Date('2025-01-29'), y: 16210 }, { x: new Date('2025-01-31'), y: 16279 }, { x: new Date('2025-02-01'), y: 16294 }, { x: new Date('2025-02-03'), y: 16294 }, { x: new Date('2025-02-04'), y: 16429 }, { x: new Date('2025-02-06'), y: 16293 }, { x: new Date('2025-02-07'), y: 16329 }, { x: new Date('2025-02-08'), y: 16297 }, { x: new Date('2025-02-09'), y: 16294 }, { x: new Date('2025-02-10'), y: 16304 }, { x: new Date('2025-02-11'), y: 16304 }, { x: new Date('2025-02-12'), y: 16336 }, { x: new Date('2025-02-13'), y: 16392 }, { x: new Date('2025-02-14'), y: 16333 }, { x: new Date('2025-02-17'), y: 16225 }, { x: new Date('2025-02-18'), y: 16224 }, { x: new Date('2025-02-19'), y: 16313 }, { x: new Date('2025-02-20'), y: 16357 }, { x: new Date('2025-02-24'), y: 16310 }, { x: new Date('2025-02-25'), y: 16287 }, { x: new Date('2025-02-26'), y: 16362 }, { x: new Date('2025-02-27'), y: 16356 }, { x: new Date('2025-02-28'), y: 16479 }, { x: new Date('2025-03-01'), y: 16573 }, { x: new Date('2025-03-02'), y: 16571 }, { x: new Date('2025-03-03'), y: 16565 }, { x: new Date('2025-03-04'), y: 16455 }, { x: new Date('2025-03-06'), y: 16319 }, { x: new Date('2025-03-07'), y: 16324 }, { x: new Date('2025-03-08'), y: 16307 }, { x: new Date('2025-03-10'), y: 16302 }, { x: new Date('2025-03-11'), y: 16377 }, { x: new Date('2025-03-12'), y: 16435.54 }, { x: new Date('2025-03-13'), y: 16437.82 }, { x: new Date('2025-03-14'), y: 16406.46 }, { x: new Date('2025-03-15'), y: 16350.23 }, { x: new Date('2025-03-16'), y: 16351.05 }, { x: new Date('2025-03-17'), y: 16351.05 }, { x: new Date('2025-03-18'), y: 16352.79 }, { x: new Date('2025-03-19'), y: 16481.57 }, { x: new Date('2025-03-20'), y: 16524.61 }, { x: new Date('2025-03-21'), y: 16500.26 }, { x: new Date('2025-03-22'), y: 16515.47 }, { x: new Date('2025-03-23'), y: 16519.95 }, { x: new Date('2025-03-24'), y: 16522.98 }, { x: new Date('2025-03-25'), y: 16522.98 }, { x: new Date('2025-03-26'), y: 16604.23 }, { x: new Date('2025-03-27'), y: 16606.66 }, { x: new Date('2025-03-28'), y: 16597.15 }, { x: new Date('2025-03-30'), y: 16601.30 }, { x: new Date('2025-03-31'), y: 16596.08 }, { x: new Date('2025-04-01'), y: 16604.18 }, { x: new Date('2025-04-02'), y: 16632.04 }, { x: new Date('2025-04-03'), y: 16663.88 }, { x: new Date('2025-04-04'), y: 16641.02 }, { x: new Date('2025-04-05'), y: 16726.75 }, { x: new Date('2025-04-06'), y: 16780.66 }, { x: new Date('2025-04-07'), y: 16757.56 }, { x: new Date('2025-04-08'), y: 16668.82 }, { x: new Date('2025-04-09'), y: 16957.19 }, { x: new Date('2025-04-10'), y: 16874.10 }, { x: new Date('2025-04-11'), y: 16847.80 }, { x: new Date('2025-04-12'), y: 16795.78 }, { x: new Date('2025-04-13'), y: 16801.18 }, { x: new Date('2025-04-14'), y: 16807.83 }, { x: new Date('2025-04-15'), y: 16780.85 }, { x: new Date('2025-04-16'), y: 16824.06 }, { x: new Date('2025-04-17'), y: 16805.78 }, { x: new Date('2025-04-18'), y: 16865.89 }, { x: new Date('2025-04-19'), y: 16858.44 }, { x: new Date('2025-04-20'), y: 16855.00 }, { x: new Date('2025-04-21'), y: 16856.27 }, { x: new Date('2025-04-22'), y: 16833.54 }, { x: new Date('2025-04-23'), y: 16865.94 }, { x: new Date('2025-04-24'), y: 16881.76 }, { x: new Date('2025-04-26'), y: 16850.73 }, { x: new Date('2025-04-27'), y: 16850.58 }, { x: new Date('2025-04-28'), y: 16837.12 }, { x: new Date('2025-05-02'), y: 16631.61 }, { x: new Date('2025-05-05'), y: 16476.97 }, { x: new Date('2025-05-06'), y: 16476.97 }, { x: new Date('2025-05-08'), y: 16440.65 }, { x: new Date('2025-05-09'), y: 16535.73 }, { x: new Date('2025-05-10'), y: 16555.64 }, { x: new Date('2025-05-11'), y: 16548.45 }, { x: new Date('2025-05-12'), y: 16552.04 }, { x: new Date('2025-05-13'), y: 16595.36 }, { x: new Date('2025-05-14'), y: 16556.57 }, { x: new Date('2025-05-15'), y: 16575.57 }, { x: new Date('2025-05-16'), y: 16505.70 }, { x: new Date('2025-05-17'), y: 16467.57 }, { x: new Date('2025-05-19'), y: 16479.29 }, { x: new Date('2025-05-20'), y: 16451.85 }, { x: new Date('2025-05-21'), y: 16419.94 }, { x: new Date('2025-05-22'), y: 16396.17 }, { x: new Date('2025-05-24'), y: 16229.86 }, { x: new Date('2025-05-26'), y: 16238.87 }, { x: new Date('2025-05-27'), y: 16232.40 }, { x: new Date('2025-06-04'), y: 16327.81 }, { x: new Date('2025-06-05'), y: 16298.45 }, { x: new Date('2025-06-06'), y: 16267.92 }, { x: new Date('2025-06-07'), y: 16303.44 }, { x: new Date('2025-06-08'), y: 16299.97 }, { x: new Date('2025-06-10'), y: 16284.64 }, { x: new Date('2025-06-11'), y: 16272.80 }, { x: new Date('2025-06-12'), y: 16269.33 }, { x: new Date('2025-06-13'), y: 16225.91 }, { x: new Date('2025-06-14'), y: 16322.73 }, { x: new Date('2025-06-15'), y: 16317.90 }, { x: new Date('2025-06-16'), y: 16303.51 }, { x: new Date('2025-06-17'), y: 16295.26 }, { x: new Date('2025-06-18'), y: 16290.56 }, { x: new Date('2025-06-20'), y: 16383.51 }, { x: new Date('2025-06-21'), y: 16393.15 }, { x: new Date('2025-06-22'), y: 16401.81 }, { x: new Date('2025-06-23'), y: 16411.70 }, { x: new Date('2025-06-24'), y: 16497.82 }, { x: new Date('2025-06-25'), y: 16326.42 }, { x: new Date('2025-06-26'), y: 16311.88 }, { x: new Date('2025-06-27'), y: 16217.50 }, { x: new Date('2025-06-28'), y: 16239.22 }, { x: new Date('2025-06-29'), y: 16236.09 }, { x: new Date('2025-06-30'), y: 16230.20 }, { x: new Date('2025-07-01'), y: 16214.17 }, { x: new Date('2025-07-02'), y: 16213.29 }, { x: new Date('2025-07-04'), y: 16204.39 }, { x: new Date('2025-07-05'), y: 16198.49 }, { x: new Date('2025-07-06'), y: 16196.74 }, { x: new Date('2025-07-07'), y: 16197.31 }, { x: new Date('2025-07-08'), y: 16253.61 }, { x: new Date('2025-07-09'), y: 16262.08 }, { x: new Date('2025-07-10'), y: 16263.74 }, { x: new Date('2025-07-12'), y: 16235.22 }, { x: new Date('2025-07-13'), y: 16234.84 }, { x: new Date('2025-07-14'), y: 16238.56 }, { x: new Date('2025-07-16'), y: 16277.69 }, { x: new Date('2025-07-17'), y: 16307.22 }, { x: new Date('2025-07-19'), y: 16316.69 }, { x: new Date('2025-07-20'), y: 16317.39 }, { x: new Date('2025-07-21'), y: 16295.98 }, { x: new Date('2025-07-22'), y: 16315.93 }, { x: new Date('2025-07-23'), y: 16287.94 }, { x: new Date('2025-07-24'), y: 16272.49 }, { x: new Date('2025-07-25'), y: 16283.17 }, { x: new Date('2025-07-26'), y: 16337.02 }, { x: new Date('2025-07-27'), y: 16333.41 }, { x: new Date('2025-07-29'), y: 16370.24 }, { x: new Date('2025-07-30'), y: 16394.58 }, { x: new Date('2025-07-31'), y: 16430.53 }, { x: new Date('2025-08-01'), y: 16485.89 }, { x: new Date('2025-08-02'), y: 16441.54 }, { x: new Date('2025-08-03'), y: 16455.27 }, { x: new Date('2025-08-04'), y: 16438.85 }, { x: new Date('2025-08-05'), y: 16384.80 }, { x: new Date('2025-08-06'), y: 16392.85 }, { x: new Date('2025-08-07'), y: 16359.01 }, { x: new Date('2025-08-08'), y: 16321.75 }, { x: new Date('2025-08-09'), y: 16301.93 }, { x: new Date('2025-08-10'), y: 16297.21 }, { x: new Date('2025-08-11'), y: 16279.02 }, { x: new Date('2025-08-12'), y: 16278.75 }, { x: new Date('2025-08-13'), y: 16264.78 }, { x: new Date('2025-08-14'), y: 16145.04 }, { x: new Date('2025-08-15'), y: 16136.08 }, { x: new Date('2025-08-16'), y: 16161.78 }, { x: new Date('2025-08-18'), y: 16184.77 }, { x: new Date('2025-08-19'), y: 16208.45 }, { x: new Date('2025-08-20'), y: 16272.49 }, { x: new Date('2025-08-21'), y: 16287.92 }, { x: new Date('2025-08-22'), y: 16328.25 }, { x: new Date('2025-08-23'), y: 16299.39 }, { x: new Date('2025-08-24'), y: 16295.91 }, { x: new Date('2025-08-25'), y: 16296.53 }, { x: new Date('2025-08-26'), y: 16265.13 }, { x: new Date('2025-08-27'), y: 16302.90 }, { x: new Date('2025-08-28'), y: 16394.37 }, { x: new Date('2025-08-29'), y: 16351.23 }, { x: new Date('2025-08-30'), y: 16484.66 }, { x: new Date('2025-08-31'), y: 16482.03 }]; 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);