const fullData = [ { x: new Date('2024-02-02'), y: 10370 }, { x: new Date('2024-02-05'), y: 10248 }, { x: new Date('2024-02-06'), y: 10235 }, { x: new Date('2024-02-07'), y: 10236 }, { x: new Date('2024-02-08'), y: 10212 }, { x: new Date('2024-02-09'), y: 10171 }, { x: new Date('2024-02-10'), y: 10186 }, { x: new Date('2024-02-12'), y: 10185 }, { x: new Date('2024-02-13'), y: 10161 }, { x: new Date('2024-02-14'), y: 10117 }, { x: new Date('2024-05-20'), y: 10701 }, { x: new Date('2024-08-01'), y: 10602 }, { x: new Date('2024-08-02'), y: 10573 }, { x: new Date('2024-08-05'), y: 10511 }, { x: new Date('2024-08-06'), y: 10528 }, { x: new Date('2024-08-07'), y: 10487 }, { x: new Date('2024-08-28'), y: 10513 }, { x: new Date('2024-08-29'), y: 10480 }, { x: new Date('2024-08-30'), y: 10521 }, { x: new Date('2024-09-02'), y: 10515 }, { x: new Date('2024-09-03'), y: 10558 }, { x: new Date('2024-09-04'), y: 10372 }, { x: new Date('2024-09-05'), y: 10367 }, { x: new Date('2024-09-05'), y: 10363 }, { x: new Date('2024-09-06'), y: 10335 }, { x: new Date('2024-09-07'), y: 10309 }, { x: new Date('2024-09-08'), y: 10309 }, { x: new Date('2024-09-09'), y: 10317 }, { x: new Date('2024-09-10'), y: 10272 }, { x: new Date('2024-09-19'), y: 10375 }, { x: new Date('2024-09-20'), y: 10288 }, { x: new Date('2024-09-23'), y: 10335 }, { x: new Date('2024-09-24'), y: 10400 }, { x: new Date('2024-09-25'), y: 10390 }, { x: new Date('2024-09-26'), y: 10384 }, { x: new Date('2024-09-27'), y: 10428 }, { x: new Date('2024-10-01'), y: 10525 }, { x: new Date('2024-10-02'), y: 10512 }, { x: new Date('2024-10-03'), y: 10578 }, { x: new Date('2024-10-04'), y: 10601 }, { x: new Date('2024-10-05'), y: 10690 }, { x: new Date('2024-10-07'), y: 10660 }, { x: new Date('2024-10-08'), y: 10574 }, { x: new Date('2024-10-10'), y: 10562 }, { x: new Date('2024-10-11'), y: 10560 }, { x: new Date('2024-10-12'), y: 10502 }, { x: new Date('2024-10-14'), y: 10479 }, { x: new Date('2024-10-15'), y: 10461 }, { x: new Date('2024-10-16'), y: 10392 }, { x: new Date('2024-10-17'), y: 10410 }, { x: new Date('2024-10-18'), y: 10394 }, { x: new Date('2024-10-19'), y: 10379 }, { x: new Date('2024-10-20'), y: 10379 }, { x: new Date('2024-10-21'), y: 10379 }, { x: new Date('2024-10-22'), y: 10376 }, { x: new Date('2024-10-23'), y: 10419 }, { x: new Date('2024-10-24'), y: 10378 }, { x: new Date('2024-10-25'), y: 10368 }, { x: new Date('2024-10-26'), y: 10358 }, { x: new Date('2024-10-27'), y: 10358 }, { x: new Date('2024-10-28'), y: 10330 }, { x: new Date('2024-10-29'), y: 10370 }, { x: new Date('2024-10-30'), y: 10329 }, { x: new Date('2024-10-31'), y: 10312 }, { x: new Date('2024-11-01'), y: 10344 }, { x: new Date('2024-11-02'), y: 10403 }, { x: new Date('2024-11-03'), y: 10403 }, { x: new Date('2024-11-04'), y: 10403 }, { x: new Date('2024-11-05'), y: 10394 }, { x: new Date('2024-11-06'), y: 10433 }, { x: new Date('2024-11-07'), y: 10395 }, { x: new Date('2024-11-08'), y: 10395 }, { x: new Date('2024-11-09'), y: 10305 }, { x: new Date('2024-11-10'), y: 10305 }, { x: new Date('2024-11-11'), y: 10331 }, { x: new Date('2024-11-12'), y: 10358 }, { x: new Date('2024-11-13'), y: 10329 }, { x: new Date('2024-11-14'), y: 10260 }, { x: new Date('2024-11-15'), y: 10306 }, { x: new Date('2024-11-16'), y: 10275 }, { x: new Date('2024-11-17'), y: 10275 }, { x: new Date('2024-11-18'), y: 10253 }, { x: new Date('2024-11-19'), y: 10298 }, { x: new Date('2024-11-21'), y: 10386 }, { x: new Date('2024-11-22'), y: 10369 }, { x: new Date('2024-11-23'), y: 10366 }, { x: new Date('2024-11-24'), y: 10366 }, { x: new Date('2024-11-26'), y: 10249 }, { x: new Date('2024-11-27'), y: 10309 }, { x: new Date('2024-11-28'), y: 10310 }, { x: new Date('2024-11-29'), y: 10318 }, { x: new Date('2024-12-01'), y: 10315 }, { x: new Date('2024-12-02'), y: 10295 }, { x: new Date('2024-12-03'), y: 10322 }, { x: new Date('2024-12-04'), y: 10271 }, { x: new Date('2024-12-06'), y: 10187 }, { x: new Date('2024-12-07'), y: 10163 }, { x: new Date('2024-12-08'), y: 10163 }, { x: new Date('2024-12-09'), y: 10163 }, { x: new Date('2024-12-10'), y: 10194 }, { x: new Date('2024-12-11'), y: 10155 }, { x: new Date('2024-12-12'), y: 10213 }, { x: new Date('2024-12-13'), y: 10161 }, { x: new Date('2024-12-14'), y: 10199 }, { x: new Date('2024-12-15'), y: 10199 }, { x: new Date('2024-12-16'), y: 10210 }, { x: new Date('2024-12-17'), y: 10217 }, { x: new Date('2024-12-18'), y: 10188 }, { x: new Date('2024-12-19'), y: 10136 }, { x: new Date('2024-12-20'), y: 10159 }, { x: new Date('2024-12-22'), y: 10114 }, { x: new Date('2024-12-23'), y: 10114 }, { x: new Date('2024-12-24'), y: 10131 }, { x: new Date('2024-12-25'), y: 10112 }, { x: new Date('2024-12-27'), y: 10096 }, { x: new Date('2024-12-30'), y: 10106 }, { x: new Date('2024-12-31'), y: 10058 }, { x: new Date('2025-01-02'), y: 10098 }, { x: new Date('2025-01-03'), y: 10086 }, { x: new Date('2025-01-04'), y: 10079 }, { x: new Date('2025-01-06'), y: 10079 }, { x: new Date('2025-01-15'), y: 10080 }, { x: new Date('2025-01-16'), y: 10198 }, { x: new Date('2025-01-17'), y: 10193 }, { x: new Date('2025-01-19'), y: 10144 }, { x: new Date('2025-01-20'), y: 10145 }, { x: new Date('2025-01-21'), y: 10251 }, { x: new Date('2025-01-22'), y: 10243 }, { x: new Date('2025-01-23'), y: 10213 }, { x: new Date('2025-01-24'), y: 10199 }, { x: new Date('2025-01-25'), y: 10209 }, { x: new Date('2025-01-26'), y: 10209 }, { x: new Date('2025-01-27'), y: 10180 }, { x: new Date('2025-01-28'), y: 10148 }, { x: new Date('2025-01-29'), y: 10133 }, { x: new Date('2025-01-31'), y: 10107 }, { x: new Date('2025-02-01'), y: 10155 }, { x: new Date('2025-02-03'), y: 10036 }, { x: new Date('2025-02-04'), y: 10153 }, { x: new Date('2025-02-06'), y: 10238 }, { x: new Date('2025-02-07'), y: 10248 }, { x: new Date('2025-02-08'), y: 10229 }, { x: new Date('2025-02-09'), y: 10231 }, { x: new Date('2025-02-10'), y: 10221 }, { x: new Date('2025-02-11'), y: 10221 }, { x: new Date('2025-02-12'), y: 10248 }, { x: new Date('2025-02-13'), y: 10282 }, { x: new Date('2025-02-14'), y: 10269 }, { x: new Date('2025-02-17'), y: 10305 }, { x: new Date('2025-02-18'), y: 10322 }, { x: new Date('2025-02-19'), y: 10361 }, { x: new Date('2025-02-20'), y: 10381 }, { x: new Date('2025-02-24'), y: 10383 }, { x: new Date('2025-02-25'), y: 10344 }, { x: new Date('2025-02-26'), y: 10374 }, { x: new Date('2025-02-27'), y: 10334 }, { x: new Date('2025-02-28'), y: 10324 }, { x: new Date('2025-03-01'), y: 10289 }, { x: new Date('2025-03-02'), y: 10290 }, { x: new Date('2025-03-03'), y: 10298 }, { x: new Date('2025-03-04'), y: 10244 }, { x: new Date('2025-03-06'), y: 10310 }, { x: new Date('2025-03-07'), y: 10343 }, { x: new Date('2025-03-08'), y: 10279 }, { x: new Date('2025-03-10'), y: 10277 }, { x: new Date('2025-03-11'), y: 10320 }, { x: new Date('2025-03-12'), y: 10344.14 }, { x: new Date('2025-03-13'), y: 10374.54 }, { x: new Date('2025-03-14'), y: 10311.32 }, { x: new Date('2025-03-15'), y: 10335.66 }, { x: new Date('2025-03-16'), y: 10332.28 }, { x: new Date('2025-03-17'), y: 10332.28 }, { x: new Date('2025-03-18'), y: 10346.05 }, { x: new Date('2025-03-19'), y: 10488.22 }, { x: new Date('2025-03-20'), y: 10488.62 }, { x: new Date('2025-03-21'), y: 10387.80 }, { x: new Date('2025-03-22'), y: 10364.79 }, { x: new Date('2025-03-23'), y: 10367.72 }, { x: new Date('2025-03-24'), y: 10379.36 }, { x: new Date('2025-03-25'), y: 10379.36 }, { x: new Date('2025-03-26'), y: 10474.34 }, { x: new Date('2025-03-27'), y: 10459.42 }, { x: new Date('2025-03-28'), y: 10458.44 }, { x: new Date('2025-03-30'), y: 10445.88 }, { x: new Date('2025-03-31'), y: 10421.23 }, { x: new Date('2025-04-01'), y: 10366.91 }, { x: new Date('2025-04-02'), y: 10431.58 }, { x: new Date('2025-04-03'), y: 10466.51 }, { x: new Date('2025-04-04'), y: 10543.88 }, { x: new Date('2025-04-05'), y: 10170.76 }, { x: new Date('2025-04-06'), y: 10210.10 }, { x: new Date('2025-04-07'), y: 10129.42 }, { x: new Date('2025-04-08'), y: 10003.73 }, { x: new Date('2025-04-09'), y: 10199.58 }, { x: new Date('2025-04-10'), y: 10262.17 }, { x: new Date('2025-04-11'), y: 10473.36 }, { x: new Date('2025-04-12'), y: 10531.94 }, { x: new Date('2025-04-13'), y: 10523.13 }, { x: new Date('2025-04-14'), y: 10563.24 }, { x: new Date('2025-04-15'), y: 10603.15 }, { x: new Date('2025-04-16'), y: 10678.64 }, { x: new Date('2025-04-17'), y: 10710.97 }, { x: new Date('2025-04-18'), y: 10759.96 }, { x: new Date('2025-04-19'), y: 10744.80 }, { x: new Date('2025-04-20'), y: 10741.46 }, { x: new Date('2025-04-21'), y: 10760.09 }, { x: new Date('2025-04-22'), y: 10800.45 }, { x: new Date('2025-04-23'), y: 10762.19 }, { x: new Date('2025-04-24'), y: 10785.54 }, { x: new Date('2025-04-26'), y: 10773.18 }, { x: new Date('2025-04-27'), y: 10771.69 }, { x: new Date('2025-04-28'), y: 10758.37 }, { x: new Date('2025-05-02'), y: 10615.53 }, { x: new Date('2025-05-05'), y: 10623.85 }, { x: new Date('2025-05-06'), y: 10623.85 }, { x: new Date('2025-05-08'), y: 10668.66 }, { x: new Date('2025-05-09'), y: 10592.63 }, { x: new Date('2025-05-10'), y: 10614.86 }, { x: new Date('2025-05-11'), y: 10608.38 }, { x: new Date('2025-05-12'), y: 10628.13 }, { x: new Date('2025-05-13'), y: 10587.72 }, { x: new Date('2025-05-14'), y: 10686.98 }, { x: new Date('2025-05-15'), y: 10679.06 }, { x: new Date('2025-05-16'), y: 10573.06 }, { x: new Date('2025-05-17'), y: 10550.22 }, { x: new Date('2025-05-19'), y: 10564.14 }, { x: new Date('2025-05-20'), y: 10613.12 }, { x: new Date('2025-05-21'), y: 10538.79 }, { x: new Date('2025-05-22'), y: 10558.30 }, { x: new Date('2025-05-24'), y: 10517.38 }, { x: new Date('2025-05-26'), y: 10537.56 }, { x: new Date('2025-05-27'), y: 10546.68 }, { x: new Date('2025-06-04'), y: 10549.84 }, { x: new Date('2025-06-05'), y: 10579.65 }, { x: new Date('2025-06-06'), y: 10588.74 }, { x: new Date('2025-06-07'), y: 10585.02 }, { x: new Date('2025-06-08'), y: 10581.85 }, { x: new Date('2025-06-10'), y: 10615.08 }, { x: new Date('2025-06-11'), y: 10615.03 }, { x: new Date('2025-06-12'), y: 10589.68 }, { x: new Date('2025-06-13'), y: 10587.21 }, { x: new Date('2025-06-14'), y: 10591.83 }, { x: new Date('2025-06-15'), y: 10587.23 }, { x: new Date('2025-06-16'), y: 10574.97 }, { x: new Date('2025-06-17'), y: 10629.41 }, { x: new Date('2025-06-18'), y: 10565.48 }, { x: new Date('2025-06-20'), y: 10611.88 }, { x: new Date('2025-06-21'), y: 10597.80 }, { x: new Date('2025-06-22'), y: 10599.58 }, { x: new Date('2025-06-23'), y: 10586.67 }, { x: new Date('2025-06-24'), y: 10638.75 }, { x: new Date('2025-06-25'), y: 10608.41 }, { x: new Date('2025-06-26'), y: 10618.61 }, { x: new Date('2025-06-27'), y: 10614.86 }, { x: new Date('2025-06-28'), y: 10607.12 }, { x: new Date('2025-06-29'), y: 10607.27 }, { x: new Date('2025-06-30'), y: 10603.99 }, { x: new Date('2025-07-01'), y: 10640.71 }, { x: new Date('2025-07-02'), y: 10669.82 }, { x: new Date('2025-07-04'), y: 10651.64 }, { x: new Date('2025-07-05'), y: 10615.13 }, { x: new Date('2025-07-06'), y: 10615.53 }, { x: new Date('2025-07-07'), y: 10613.39 }, { x: new Date('2025-07-08'), y: 10566.03 }, { x: new Date('2025-07-09'), y: 10619.81 }, { x: new Date('2025-07-10'), y: 10625.04 }, { x: new Date('2025-07-12'), y: 10676.93 }, { x: new Date('2025-07-13'), y: 10675.78 }, { x: new Date('2025-07-14'), y: 10673.27 }, { x: new Date('2025-07-16'), y: 10629.79 }, { x: new Date('2025-07-17'), y: 10636.13 }, { x: new Date('2025-07-19'), y: 10626.20 }, { x: new Date('2025-07-20'), y: 10622.82 }, { x: new Date('2025-07-21'), y: 10608.38 }, { x: new Date('2025-07-22'), y: 10645.56 }, { x: new Date('2025-07-23'), y: 10654.40 }, { x: new Date('2025-07-24'), y: 10735.75 }, { x: new Date('2025-07-25'), y: 10750.25 }, { x: new Date('2025-07-26'), y: 10725.95 }, { x: new Date('2025-07-27'), y: 10725.34 }, { x: new Date('2025-07-29'), y: 10678.44 }, { x: new Date('2025-07-30'), y: 10670.00 }, { x: new Date('2025-07-31'), y: 10613.75 }, { x: new Date('2025-08-01'), y: 10607.93 }, { x: new Date('2025-08-02'), y: 10614.01 }, { x: new Date('2025-08-03'), y: 10613.04 }, { x: new Date('2025-08-04'), y: 10617.55 }, { x: new Date('2025-08-05'), y: 10607.70 }, { x: new Date('2025-08-06'), y: 10603.81 }, { x: new Date('2025-08-07'), y: 10635.42 }, { x: new Date('2025-08-08'), y: 10645.11 }, { x: new Date('2025-08-09'), y: 10633.40 }, { x: new Date('2025-08-10'), y: 10629.72 }, { x: new Date('2025-08-11'), y: 10614.26 }, { x: new Date('2025-08-12'), y: 10601.67 }, { x: new Date('2025-08-13'), y: 10600.65 }, { x: new Date('2025-08-14'), y: 10583.80 }, { x: new Date('2025-08-15'), y: 10503.63 }, { x: new Date('2025-08-16'), y: 10521.68 }, { x: new Date('2025-08-18'), y: 10537.66 }, { x: new Date('2025-08-19'), y: 10530.13 }, { x: new Date('2025-08-20'), y: 10519.80 }, { x: new Date('2025-08-21'), y: 10480.42 }, { x: new Date('2025-08-22'), y: 10488.26 }, { x: new Date('2025-08-23'), y: 10548.41 }, { x: new Date('2025-08-24'), y: 10542.35 }, { x: new Date('2025-08-25'), y: 10561.15 }, { x: new Date('2025-08-26'), y: 10552.01 }, { x: new Date('2025-08-27'), y: 10585.26 }, { x: new Date('2025-08-28'), y: 10649.29 }, { x: new Date('2025-08-29'), y: 10675.55 }, { x: new Date('2025-08-30'), y: 10779.56 }, { x: new Date('2025-08-31'), y: 10775.52 }]; 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);