const fullData = [ { x: new Date('2024-02-02'), y: 20000 }, { x: new Date('2024-02-05'), y: 19869 }, { x: new Date('2024-02-06'), y: 19747 }, { x: new Date('2024-02-07'), y: 19764 }, { x: new Date('2024-02-08'), y: 19760 }, { x: new Date('2024-02-09'), y: 19765 }, { x: new Date('2024-02-10'), y: 19715 }, { x: new Date('2024-02-12'), y: 19724 }, { x: new Date('2024-02-13'), y: 19652 }, { x: new Date('2024-02-14'), y: 19720 }, { x: new Date('2024-05-20'), y: 20296 }, { x: new Date('2024-08-01'), y: 20830 }, { x: new Date('2024-08-02'), y: 20676 }, { x: new Date('2024-08-05'), y: 20682 }, { x: new Date('2024-08-06'), y: 20678 }, { x: new Date('2024-08-07'), y: 20354 }, { x: new Date('2024-08-28'), y: 20495 }, { x: new Date('2024-08-29'), y: 20342 }, { x: new Date('2024-08-30'), y: 20389 }, { x: new Date('2024-09-02'), y: 20400 }, { x: new Date('2024-09-03'), y: 20456 }, { x: new Date('2024-09-04'), y: 20292 }, { x: new Date('2024-09-05'), y: 20267 }, { x: new Date('2024-09-05'), y: 20274 }, { x: new Date('2024-09-06'), y: 20238 }, { x: new Date('2024-09-07'), y: 20298 }, { x: new Date('2024-09-08'), y: 20298 }, { x: new Date('2024-09-09'), y: 20272 }, { x: new Date('2024-09-10'), y: 20169 }, { x: new Date('2024-09-19'), y: 20234 }, { x: new Date('2024-09-20'), y: 20059 }, { x: new Date('2024-09-23'), y: 20184 }, { x: new Date('2024-09-24'), y: 20278 }, { x: new Date('2024-09-25'), y: 20242 }, { x: new Date('2024-09-26'), y: 20253 }, { x: new Date('2024-09-27'), y: 20290 }, { x: new Date('2024-10-01'), y: 20338 }, { x: new Date('2024-10-02'), y: 20232 }, { x: new Date('2024-10-03'), y: 20308 }, { x: new Date('2024-10-04'), y: 20328 }, { x: new Date('2024-10-05'), y: 20561 }, { x: new Date('2024-10-07'), y: 20565 }, { x: new Date('2024-10-08'), y: 20566 }, { x: new Date('2024-10-10'), y: 20529 }, { x: new Date('2024-10-11'), y: 20458 }, { x: new Date('2024-10-12'), y: 20347 }, { x: new Date('2024-10-14'), y: 20305 }, { x: new Date('2024-10-15'), y: 20330 }, { x: new Date('2024-10-16'), y: 20331 }, { x: new Date('2024-10-17'), y: 20223 }, { x: new Date('2024-10-18'), y: 20199 }, { x: new Date('2024-10-19'), y: 20187 }, { x: new Date('2024-10-20'), y: 20187 }, { x: new Date('2024-10-21'), y: 20187 }, { x: new Date('2024-10-22'), y: 20207 }, { x: new Date('2024-10-23'), y: 20235 }, { x: new Date('2024-10-24'), y: 20205 }, { x: new Date('2024-10-25'), y: 20275 }, { x: new Date('2024-10-26'), y: 20362 }, { x: new Date('2024-10-27'), y: 20362 }, { x: new Date('2024-10-28'), y: 20268 }, { x: new Date('2024-10-29'), y: 20427 }, { x: new Date('2024-10-30'), y: 20496 }, { x: new Date('2024-10-31'), y: 20327 }, { x: new Date('2024-11-01'), y: 20279 }, { x: new Date('2024-11-02'), y: 20488 }, { x: new Date('2024-11-03'), y: 20488 }, { x: new Date('2024-11-04'), y: 20488 }, { x: new Date('2024-11-05'), y: 20462 }, { x: new Date('2024-11-06'), y: 20477 }, { x: new Date('2024-11-07'), y: 20392 }, { x: new Date('2024-11-08'), y: 20210 }, { x: new Date('2024-11-09'), y: 20228 }, { x: new Date('2024-11-10'), y: 20228 }, { x: new Date('2024-11-11'), y: 20241 }, { x: new Date('2024-11-12'), y: 20299 }, { x: new Date('2024-11-13'), y: 20156 }, { x: new Date('2024-11-14'), y: 20088 }, { x: new Date('2024-11-15'), y: 20237 }, { x: new Date('2024-11-16'), y: 20061 }, { x: new Date('2024-11-17'), y: 20061 }, { x: new Date('2024-11-18'), y: 20029 }, { x: new Date('2024-11-19'), y: 20079 }, { x: new Date('2024-11-21'), y: 20145 }, { x: new Date('2024-11-22'), y: 20041 }, { x: new Date('2024-11-23'), y: 19965 }, { x: new Date('2024-11-24'), y: 19965 }, { x: new Date('2024-11-26'), y: 19891 }, { x: new Date('2024-11-27'), y: 20016 }, { x: new Date('2024-11-28'), y: 20091 }, { x: new Date('2024-11-29'), y: 20140 }, { x: new Date('2024-12-01'), y: 20156 }, { x: new Date('2024-12-02'), y: 20104 }, { x: new Date('2024-12-03'), y: 20168 }, { x: new Date('2024-12-04'), y: 20234 }, { x: new Date('2024-12-06'), y: 20198 }, { x: new Date('2024-12-07'), y: 20161 }, { x: new Date('2024-12-08'), y: 20161 }, { x: new Date('2024-12-09'), y: 20161 }, { x: new Date('2024-12-10'), y: 20213 }, { x: new Date('2024-12-11'), y: 20333 }, { x: new Date('2024-12-12'), y: 20360 }, { x: new Date('2024-12-13'), y: 20220 }, { x: new Date('2024-12-14'), y: 20222 }, { x: new Date('2024-12-15'), y: 20222 }, { x: new Date('2024-12-16'), y: 20247 }, { x: new Date('2024-12-17'), y: 20357 }, { x: new Date('2024-12-18'), y: 20448 }, { x: new Date('2024-12-19'), y: 20490 }, { x: new Date('2024-12-20'), y: 20390 }, { x: new Date('2024-12-22'), y: 20362 }, { x: new Date('2024-12-23'), y: 20362 }, { x: new Date('2024-12-24'), y: 20343 }, { x: new Date('2024-12-25'), y: 20336 }, { x: new Date('2024-12-27'), y: 20332 }, { x: new Date('2024-12-30'), y: 20420 }, { x: new Date('2024-12-31'), y: 20269 }, { x: new Date('2025-01-02'), y: 20345 }, { x: new Date('2025-01-03'), y: 20114 }, { x: new Date('2025-01-04'), y: 20119 }, { x: new Date('2025-01-06'), y: 20119 }, { x: new Date('2025-01-15'), y: 19881 }, { x: new Date('2025-01-16'), y: 20029 }, { x: new Date('2025-01-17'), y: 20083 }, { x: new Date('2025-01-19'), y: 19956 }, { x: new Date('2025-01-20'), y: 19932 }, { x: new Date('2025-01-21'), y: 20114 }, { x: new Date('2025-01-22'), y: 20154 }, { x: new Date('2025-01-23'), y: 20046 }, { x: new Date('2025-01-24'), y: 20056 }, { x: new Date('2025-01-25'), y: 20180 }, { x: new Date('2025-01-26'), y: 20181 }, { x: new Date('2025-01-27'), y: 20151 }, { x: new Date('2025-01-28'), y: 20184 }, { x: new Date('2025-01-29'), y: 20171 }, { x: new Date('2025-01-31'), y: 20231 }, { x: new Date('2025-02-01'), y: 20192 }, { x: new Date('2025-02-03'), y: 20103 }, { x: new Date('2025-02-04'), y: 20289 }, { x: new Date('2025-02-06'), y: 20366 }, { x: new Date('2025-02-07'), y: 20245 }, { x: new Date('2025-02-08'), y: 20209 }, { x: new Date('2025-02-09'), y: 20223 }, { x: new Date('2025-02-10'), y: 20174 }, { x: new Date('2025-02-11'), y: 20174 }, { x: new Date('2025-02-12'), y: 20192 }, { x: new Date('2025-02-13'), y: 20383 }, { x: new Date('2025-02-14'), y: 20486 }, { x: new Date('2025-02-17'), y: 20447 }, { x: new Date('2025-02-18'), y: 20442 }, { x: new Date('2025-02-19'), y: 20549 }, { x: new Date('2025-02-20'), y: 20568 }, { x: new Date('2025-02-24'), y: 20623 }, { x: new Date('2025-02-25'), y: 20558 }, { x: new Date('2025-02-26'), y: 20691 }, { x: new Date('2025-02-27'), y: 20708 }, { x: new Date('2025-02-28'), y: 20748 }, { x: new Date('2025-03-01'), y: 20867 }, { x: new Date('2025-03-02'), y: 20866 }, { x: new Date('2025-03-03'), y: 20862 }, { x: new Date('2025-03-04'), y: 20863 }, { x: new Date('2025-03-06'), y: 20995 }, { x: new Date('2025-03-07'), y: 21003 }, { x: new Date('2025-03-08'), y: 21060 }, { x: new Date('2025-03-10'), y: 21043 }, { x: new Date('2025-03-11'), y: 21108 }, { x: new Date('2025-03-12'), y: 21245.42 }, { x: new Date('2025-03-13'), y: 21274.02 }, { x: new Date('2025-03-14'), y: 21240.02 }, { x: new Date('2025-03-15'), y: 21146.06 }, { x: new Date('2025-03-16'), y: 21146.81 }, { x: new Date('2025-03-17'), y: 21146.81 }, { x: new Date('2025-03-18'), y: 21155.03 }, { x: new Date('2025-03-19'), y: 21370.96 }, { x: new Date('2025-03-20'), y: 21429.68 }, { x: new Date('2025-03-21'), y: 21368.14 }, { x: new Date('2025-03-22'), y: 21326.89 }, { x: new Date('2025-03-23'), y: 21329.92 }, { x: new Date('2025-03-24'), y: 21319.82 }, { x: new Date('2025-03-25'), y: 21319.82 }, { x: new Date('2025-03-26'), y: 21490.12 }, { x: new Date('2025-03-27'), y: 21389.43 }, { x: new Date('2025-03-28'), y: 21474.23 }, { x: new Date('2025-03-30'), y: 21482.08 }, { x: new Date('2025-03-31'), y: 21443.46 }, { x: new Date('2025-04-01'), y: 21414.89 }, { x: new Date('2025-04-02'), y: 21404.28 }, { x: new Date('2025-04-03'), y: 21578.21 }, { x: new Date('2025-04-04'), y: 21785.14 }, { x: new Date('2025-04-05'), y: 21353.31 }, { x: new Date('2025-04-06'), y: 21369.63 }, { x: new Date('2025-04-07'), y: 21280.58 }, { x: new Date('2025-04-08'), y: 21113.22 }, { x: new Date('2025-04-09'), y: 21580.01 }, { x: new Date('2025-04-10'), y: 21595.58 }, { x: new Date('2025-04-11'), y: 21794.68 }, { x: new Date('2025-04-12'), y: 21956.84 }, { x: new Date('2025-04-13'), y: 21977.76 }, { x: new Date('2025-04-14'), y: 21972.82 }, { x: new Date('2025-04-15'), y: 22085.59 }, { x: new Date('2025-04-16'), y: 22245.93 }, { x: new Date('2025-04-17'), y: 22252.84 }, { x: new Date('2025-04-18'), y: 22337.00 }, { x: new Date('2025-04-19'), y: 22343.03 }, { x: new Date('2025-04-20'), y: 22342.69 }, { x: new Date('2025-04-21'), y: 22392.89 }, { x: new Date('2025-04-22'), y: 22516.32 }, { x: new Date('2025-04-23'), y: 22479.74 }, { x: new Date('2025-04-24'), y: 22428.82 }, { x: new Date('2025-04-26'), y: 22446.21 }, { x: new Date('2025-04-27'), y: 22444.16 }, { x: new Date('2025-04-28'), y: 22404.07 }, { x: new Date('2025-05-02'), y: 22115.08 }, { x: new Date('2025-05-05'), y: 21848.17 }, { x: new Date('2025-05-06'), y: 21848.17 }, { x: new Date('2025-05-08'), y: 21951.13 }, { x: new Date('2025-05-09'), y: 21931.69 }, { x: new Date('2025-05-10'), y: 21994.97 }, { x: new Date('2025-05-11'), y: 21978.18 }, { x: new Date('2025-05-12'), y: 21960.72 }, { x: new Date('2025-05-13'), y: 21793.94 }, { x: new Date('2025-05-14'), y: 21892.25 }, { x: new Date('2025-05-15'), y: 22037.65 }, { x: new Date('2025-05-16'), y: 21927.99 }, { x: new Date('2025-05-17'), y: 21840.94 }, { x: new Date('2025-05-19'), y: 21868.07 }, { x: new Date('2025-05-20'), y: 21973.61 }, { x: new Date('2025-05-21'), y: 21948.64 }, { x: new Date('2025-05-22'), y: 21928.05 }, { x: new Date('2025-05-24'), y: 21905.17 }, { x: new Date('2025-05-26'), y: 21882.36 }, { x: new Date('2025-05-27'), y: 21977.52 }, { x: new Date('2025-06-04'), y: 22046.54 }, { x: new Date('2025-06-05'), y: 22066.01 }, { x: new Date('2025-06-06'), y: 22083.15 }, { x: new Date('2025-06-07'), y: 22045.28 }, { x: new Date('2025-06-08'), y: 22048.29 }, { x: new Date('2025-06-10'), y: 22066.99 }, { x: new Date('2025-06-11'), y: 21974.86 }, { x: new Date('2025-06-12'), y: 22011.96 }, { x: new Date('2025-06-13'), y: 22054.31 }, { x: new Date('2025-06-14'), y: 22144.90 }, { x: new Date('2025-06-15'), y: 22128.21 }, { x: new Date('2025-06-16'), y: 22088.14 }, { x: new Date('2025-06-17'), y: 22127.14 }, { x: new Date('2025-06-18'), y: 21922.96 }, { x: new Date('2025-06-20'), y: 22019.81 }, { x: new Date('2025-06-21'), y: 22066.56 }, { x: new Date('2025-06-22'), y: 22071.68 }, { x: new Date('2025-06-23'), y: 22049.87 }, { x: new Date('2025-06-24'), y: 22248.88 }, { x: new Date('2025-06-25'), y: 22240.32 }, { x: new Date('2025-06-26'), y: 22253.34 }, { x: new Date('2025-06-27'), y: 22270.89 }, { x: new Date('2025-06-28'), y: 22265.82 }, { x: new Date('2025-06-29'), y: 22260.84 }, { x: new Date('2025-06-30'), y: 22243.56 }, { x: new Date('2025-07-01'), y: 22258.70 }, { x: new Date('2025-07-02'), y: 22272.70 }, { x: new Date('2025-07-04'), y: 22107.43 }, { x: new Date('2025-07-05'), y: 22101.84 }, { x: new Date('2025-07-06'), y: 22103.37 }, { x: new Date('2025-07-07'), y: 22091.29 }, { x: new Date('2025-07-08'), y: 22112.89 }, { x: new Date('2025-07-09'), y: 22066.06 }, { x: new Date('2025-07-10'), y: 22100.99 }, { x: new Date('2025-07-12'), y: 21930.73 }, { x: new Date('2025-07-13'), y: 21921.83 }, { x: new Date('2025-07-14'), y: 21929.62 }, { x: new Date('2025-07-16'), y: 21832.35 }, { x: new Date('2025-07-17'), y: 21846.62 }, { x: new Date('2025-07-19'), y: 21905.44 }, { x: new Date('2025-07-20'), y: 21904.23 }, { x: new Date('2025-07-21'), y: 21878.55 }, { x: new Date('2025-07-22'), y: 21988.09 }, { x: new Date('2025-07-23'), y: 21996.58 }, { x: new Date('2025-07-24'), y: 22049.71 }, { x: new Date('2025-07-25'), y: 22015.90 }, { x: new Date('2025-07-26'), y: 21928.52 }, { x: new Date('2025-07-27'), y: 21934.59 }, { x: new Date('2025-07-29'), y: 21893.75 }, { x: new Date('2025-07-30'), y: 21880.18 }, { x: new Date('2025-07-31'), y: 21839.39 }, { x: new Date('2025-08-01'), y: 21785.60 }, { x: new Date('2025-08-02'), y: 21788.58 }, { x: new Date('2025-08-03'), y: 21777.14 }, { x: new Date('2025-08-04'), y: 21842.33 }, { x: new Date('2025-08-05'), y: 21770.77 }, { x: new Date('2025-08-06'), y: 21785.59 }, { x: new Date('2025-08-07'), y: 21813.03 }, { x: new Date('2025-08-08'), y: 21911.08 }, { x: new Date('2025-08-09'), y: 21930.10 }, { x: new Date('2025-08-10'), y: 21912.47 }, { x: new Date('2025-08-11'), y: 21884.02 }, { x: new Date('2025-08-12'), y: 21841.33 }, { x: new Date('2025-08-13'), y: 21935.54 }, { x: new Date('2025-08-14'), y: 21959.52 }, { x: new Date('2025-08-15'), y: 21836.67 }, { x: new Date('2025-08-16'), y: 21865.20 }, { x: new Date('2025-08-18'), y: 21902.41 }, { x: new Date('2025-08-19'), y: 21872.42 }, { x: new Date('2025-08-20'), y: 21957.54 }, { x: new Date('2025-08-21'), y: 21934.75 }, { x: new Date('2025-08-22'), y: 21917.84 }, { x: new Date('2025-08-23'), y: 22009.21 }, { x: new Date('2025-08-24'), y: 21994.38 }, { x: new Date('2025-08-25'), y: 22040.90 }, { x: new Date('2025-08-26'), y: 21924.31 }, { x: new Date('2025-08-27'), y: 21967.16 }, { x: new Date('2025-08-28'), y: 22098.11 }, { x: new Date('2025-08-29'), y: 22087.83 }, { x: new Date('2025-08-30'), y: 22263.84 }, { x: new Date('2025-08-31'), y: 22242.67 }]; 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);