const fullData = [ { x: new Date('2024-02-02'), y: 17121 }, { x: new Date('2024-02-05'), y: 16966 }, { x: new Date('2024-02-06'), y: 16918 }, { x: new Date('2024-02-07'), y: 16876 }, { x: new Date('2024-02-08'), y: 16865 }, { x: new Date('2024-02-09'), y: 16879 }, { x: new Date('2024-02-10'), y: 16828 }, { x: new Date('2024-02-12'), y: 16852 }, { x: new Date('2024-02-13'), y: 16770 }, { x: new Date('2024-02-14'), y: 16773 }, { x: new Date('2024-05-20'), y: 17373 }, { x: new Date('2024-08-01'), y: 17572 }, { x: new Date('2024-08-02'), y: 17538 }, { x: new Date('2024-08-05'), y: 17655 }, { x: new Date('2024-08-06'), y: 17731 }, { x: new Date('2024-08-07'), y: 17517 }, { x: new Date('2024-08-28'), y: 17272 }, { x: new Date('2024-08-29'), y: 17148 }, { x: new Date('2024-08-30'), y: 17105 }, { x: new Date('2024-09-02'), y: 17157 }, { x: new Date('2024-09-03'), y: 17205 }, { x: new Date('2024-09-04'), y: 17178 }, { x: new Date('2024-09-05'), y: 17130 }, { x: new Date('2024-09-05'), y: 17111 }, { x: new Date('2024-09-06'), y: 17111 }, { x: new Date('2024-09-07'), y: 17110 }, { x: new Date('2024-09-08'), y: 17105 }, { x: new Date('2024-09-09'), y: 17105 }, { x: new Date('2024-09-10'), y: 17085 }, { x: new Date('2024-09-19'), y: 17026 }, { x: new Date('2024-09-20'), y: 16849 }, { x: new Date('2024-09-23'), y: 16916 }, { x: new Date('2024-09-24'), y: 16873 }, { x: new Date('2024-09-25'), y: 16888 }, { x: new Date('2024-09-26'), y: 16928 }, { x: new Date('2024-09-27'), y: 16926 }, { x: new Date('2024-10-01'), y: 16929 }, { x: new Date('2024-10-02'), y: 16853 }, { x: new Date('2024-10-03'), y: 16992 }, { x: new Date('2024-10-04'), y: 17074 }, { x: new Date('2024-10-05'), y: 17206 }, { x: new Date('2024-10-07'), y: 17189 }, { x: new Date('2024-10-08'), y: 17243 }, { x: new Date('2024-10-10'), y: 17186 }, { x: new Date('2024-10-11'), y: 17133 }, { x: new Date('2024-10-12'), y: 17047 }, { x: new Date('2024-10-14'), y: 16995 }, { x: new Date('2024-10-15'), y: 16971 }, { x: new Date('2024-10-16'), y: 16959 }, { x: new Date('2024-10-17'), y: 16902 }, { x: new Date('2024-10-18'), y: 16860 }, { x: new Date('2024-10-19'), y: 16800 }, { x: new Date('2024-10-20'), y: 16803 }, { x: new Date('2024-10-21'), y: 16803 }, { x: new Date('2024-10-22'), y: 16817 }, { x: new Date('2024-10-23'), y: 16805 }, { x: new Date('2024-10-24'), y: 16848 }, { x: new Date('2024-10-25'), y: 16805 }, { x: new Date('2024-10-26'), y: 16988 }, { x: new Date('2024-10-27'), y: 16988 }, { x: new Date('2024-10-28'), y: 16988 }, { x: new Date('2024-10-29'), y: 17027 }, { x: new Date('2024-10-30'), y: 17036 }, { x: new Date('2024-10-31'), y: 16947 }, { x: new Date('2024-11-01'), y: 17048 }, { x: new Date('2024-11-02'), y: 17640 }, { x: new Date('2024-11-03'), y: 17110 }, { x: new Date('2024-11-04'), y: 17110 }, { x: new Date('2024-11-05'), y: 17205 }, { x: new Date('2024-11-06'), y: 17175 }, { x: new Date('2024-11-07'), y: 17113 }, { x: new Date('2024-11-08'), y: 16930 }, { x: new Date('2024-11-09'), y: 16808 }, { x: new Date('2024-11-10'), y: 16808 }, { x: new Date('2024-11-11'), y: 16808 }, { x: new Date('2024-11-12'), y: 16738 }, { x: new Date('2024-11-13'), y: 16775 }, { x: new Date('2024-11-14'), y: 16724 }, { x: new Date('2024-11-15'), y: 16796 }, { x: new Date('2024-11-16'), y: 16819 }, { x: new Date('2024-11-17'), y: 16819 }, { x: new Date('2024-11-18'), y: 16819 }, { x: new Date('2024-11-19'), y: 16707 }, { x: new Date('2024-11-21'), y: 16800 }, { x: new Date('2024-11-22'), y: 16730 }, { x: new Date('2024-11-23'), y: 16534 }, { x: new Date('2024-11-24'), y: 16583 }, { x: new Date('2024-11-26'), y: 16534 }, { x: new Date('2024-11-27'), y: 16709 }, { x: new Date('2024-11-28'), y: 16705 }, { x: new Date('2024-11-29'), y: 16751 }, { x: new Date('2024-12-01'), y: 16750 }, { x: new Date('2024-12-02'), y: 16750 }, { x: new Date('2024-12-03'), y: 16723 }, { x: new Date('2024-12-04'), y: 16765 }, { x: new Date('2024-12-06'), y: 16715 }, { x: new Date('2024-12-07'), y: 16740 }, { x: new Date('2024-12-08'), y: 16740 }, { x: new Date('2024-12-09'), y: 16740 }, { x: new Date('2024-12-10'), y: 16787 }, { x: new Date('2024-12-11'), y: 16714 }, { x: new Date('2024-12-12'), y: 16741 }, { x: new Date('2024-12-13'), y: 16771 }, { x: new Date('2024-12-14'), y: 16811 }, { x: new Date('2024-12-15'), y: 16811 }, { x: new Date('2024-12-16'), y: 16811 }, { x: new Date('2024-12-17'), y: 16808 }, { x: new Date('2024-12-18'), y: 16947 }, { x: new Date('2024-12-19'), y: 16888 }, { x: new Date('2024-12-20'), y: 16991 }, { x: new Date('2024-12-22'), y: 16859 }, { x: new Date('2024-12-23'), y: 16859 }, { x: new Date('2024-12-24'), y: 16830 }, { x: new Date('2024-12-25'), y: 16855 }, { x: new Date('2024-12-27'), y: 16855 }, { x: new Date('2024-12-30'), y: 16928 }, { x: new Date('2024-12-31'), y: 16889 }, { x: new Date('2025-01-02'), y: 16889 }, { x: new Date('2025-01-03'), y: 16756 }, { x: new Date('2025-01-04'), y: 16701 }, { x: new Date('2025-01-06'), y: 16701 }, { x: new Date('2025-01-15'), y: 16729 }, { x: new Date('2025-01-16'), y: 16861 }, { x: new Date('2025-01-17'), y: 16851 }, { x: new Date('2025-01-19'), y: 16899 }, { x: new Date('2025-01-20'), y: 16899 }, { x: new Date('2025-01-21'), y: 16935 }, { x: new Date('2025-01-22'), y: 17009 }, { x: new Date('2025-01-23'), y: 16958 }, { x: new Date('2025-01-24'), y: 16906 }, { x: new Date('2025-01-25'), y: 16901 }, { x: new Date('2025-01-26'), y: 16901 }, { x: new Date('2025-01-27'), y: 16901 }, { x: new Date('2025-01-28'), y: 17008 }, { x: new Date('2025-01-29'), y: 16886 }, { x: new Date('2025-01-31'), y: 16881 }, { x: new Date('2025-02-01'), y: 16902 }, { x: new Date('2025-02-03'), y: 16659 }, { x: new Date('2025-02-04'), y: 16429 }, { x: new Date('2025-02-06'), y: 16948 }, { x: new Date('2025-02-07'), y: 16908 }, { x: new Date('2025-02-08'), y: 16853 }, { x: new Date('2025-02-09'), y: 16866 }, { x: new Date('2025-02-10'), y: 16790 }, { x: new Date('2025-02-11'), y: 16790 }, { x: new Date('2025-02-12'), y: 16822 }, { x: new Date('2025-02-13'), y: 17003 }, { x: new Date('2025-02-14'), y: 17037 }, { x: new Date('2025-02-17'), y: 17040 }, { x: new Date('2025-02-18'), y: 16993 }, { x: new Date('2025-02-19'), y: 17026 }, { x: new Date('2025-02-20'), y: 17036 }, { x: new Date('2025-02-24'), y: 17072 }, { x: new Date('2025-02-25'), y: 17037 }, { x: new Date('2025-02-26'), y: 17167 }, { x: new Date('2025-02-27'), y: 17147 }, { x: new Date('2025-02-28'), y: 17128 }, { x: new Date('2025-03-01'), y: 17224 }, { x: new Date('2025-03-02'), y: 17224 }, { x: new Date('2025-03-03'), y: 17225 }, { x: new Date('2025-03-04'), y: 17224 }, { x: new Date('2025-03-06'), y: 17553 }, { x: new Date('2025-03-07'), y: 17602 }, { x: new Date('2025-03-08'), y: 17688 }, { x: new Date('2025-03-10'), y: 17687 }, { x: new Date('2025-03-11'), y: 17737 }, { x: new Date('2025-03-12'), y: 17921.56 }, { x: new Date('2025-03-13'), y: 17890.29 }, { x: new Date('2025-03-14'), y: 17805.35 }, { x: new Date('2025-03-15'), y: 17788.99 }, { x: new Date('2025-03-16'), y: 17784.59 }, { x: new Date('2025-03-17'), y: 17784.59 }, { x: new Date('2025-03-18'), y: 17800.09 }, { x: new Date('2025-03-19'), y: 17987.78 }, { x: new Date('2025-03-20'), y: 17992.85 }, { x: new Date('2025-03-21'), y: 17885.07 }, { x: new Date('2025-03-22'), y: 17859.87 }, { x: new Date('2025-03-23'), y: 17861.65 }, { x: new Date('2025-03-24'), y: 17861.98 }, { x: new Date('2025-03-25'), y: 17861.98 }, { x: new Date('2025-03-26'), y: 17937.15 }, { x: new Date('2025-03-27'), y: 17870.14 }, { x: new Date('2025-03-28'), y: 17899.67 }, { x: new Date('2025-03-30'), y: 17933.86 }, { x: new Date('2025-03-31'), y: 17918.39 }, { x: new Date('2025-04-01'), y: 17915.67 }, { x: new Date('2025-04-02'), y: 17895.29 }, { x: new Date('2025-04-03'), y: 18035.93 }, { x: new Date('2025-04-04'), y: 18285.64 }, { x: new Date('2025-04-05'), y: 18147.09 }, { x: new Date('2025-04-06'), y: 18161.35 }, { x: new Date('2025-04-07'), y: 18122.82 }, { x: new Date('2025-04-08'), y: 18077.70 }, { x: new Date('2025-04-09'), y: 18498.74 }, { x: new Date('2025-04-10'), y: 18565.47 }, { x: new Date('2025-04-11'), y: 18735.73 }, { x: new Date('2025-04-12'), y: 19016.24 }, { x: new Date('2025-04-13'), y: 19021.31 }, { x: new Date('2025-04-14'), y: 19050.08 }, { x: new Date('2025-04-15'), y: 19040.19 }, { x: new Date('2025-04-16'), y: 19015.39 }, { x: new Date('2025-04-17'), y: 19109.29 }, { x: new Date('2025-04-18'), y: 19160.06 }, { x: new Date('2025-04-19'), y: 19162.57 }, { x: new Date('2025-04-20'), y: 19160.68 }, { x: new Date('2025-04-21'), y: 19246.87 }, { x: new Date('2025-04-22'), y: 19374.76 }, { x: new Date('2025-04-23'), y: 19268.32 }, { x: new Date('2025-04-24'), y: 19189.73 }, { x: new Date('2025-04-26'), y: 19149.93 }, { x: new Date('2025-04-27'), y: 19148.08 }, { x: new Date('2025-04-28'), y: 19119.92 }, { x: new Date('2025-05-02'), y: 18801.40 }, { x: new Date('2025-05-05'), y: 18630.48 }, { x: new Date('2025-05-06'), y: 18630.48 }, { x: new Date('2025-05-08'), y: 18631.80 }, { x: new Date('2025-05-09'), y: 18597.55 }, { x: new Date('2025-05-10'), y: 18623.89 }, { x: new Date('2025-05-11'), y: 18615.59 }, { x: new Date('2025-05-12'), y: 18573.15 }, { x: new Date('2025-05-13'), y: 18318.13 }, { x: new Date('2025-05-14'), y: 18410.51 }, { x: new Date('2025-05-15'), y: 18565.36 }, { x: new Date('2025-05-16'), y: 18459.98 }, { x: new Date('2025-05-17'), y: 18368.26 }, { x: new Date('2025-05-19'), y: 18399.76 }, { x: new Date('2025-05-20'), y: 18489.35 }, { x: new Date('2025-05-21'), y: 18484.95 }, { x: new Date('2025-05-22'), y: 18585.60 }, { x: new Date('2025-05-24'), y: 18387.27 }, { x: new Date('2025-05-26'), y: 18362.69 }, { x: new Date('2025-05-27'), y: 18448.57 }, { x: new Date('2025-06-04'), y: 18569.55 }, { x: new Date('2025-06-05'), y: 18588.15 }, { x: new Date('2025-06-06'), y: 18601.11 }, { x: new Date('2025-06-07'), y: 18571.25 }, { x: new Date('2025-06-08'), y: 18575.68 }, { x: new Date('2025-06-10'), y: 18591.25 }, { x: new Date('2025-06-11'), y: 18597.41 }, { x: new Date('2025-06-12'), y: 18662.45 }, { x: new Date('2025-06-13'), y: 18790.84 }, { x: new Date('2025-06-14'), y: 18840.07 }, { x: new Date('2025-06-15'), y: 18824.68 }, { x: new Date('2025-06-16'), y: 18798.89 }, { x: new Date('2025-06-17'), y: 18850.72 }, { x: new Date('2025-06-18'), y: 18713.51 }, { x: new Date('2025-06-20'), y: 18822 }, { x: new Date('2025-06-21'), y: 18865.44 }, { x: new Date('2025-06-22'), y: 18868.19 }, { x: new Date('2025-06-23'), y: 18864.48 }, { x: new Date('2025-06-24'), y: 19048.61 }, { x: new Date('2025-06-25'), y: 18965.36 }, { x: new Date('2025-06-26'), y: 18980.19 }, { x: new Date('2025-06-27'), y: 18989.47 }, { x: new Date('2025-06-28'), y: 18984.38 }, { x: new Date('2025-06-29'), y: 18980.84 }, { x: new Date('2025-06-30'), y: 18999.06 }, { x: new Date('2025-07-01'), y: 19074.68 }, { x: new Date('2025-07-02'), y: 19119.01 }, { x: new Date('2025-07-04'), y: 19058.62 }, { x: new Date('2025-07-05'), y: 19064.85 }, { x: new Date('2025-07-06'), y: 19063.44 }, { x: new Date('2025-07-07'), y: 19059.70 }, { x: new Date('2025-07-08'), y: 19048.56 }, { x: new Date('2025-07-09'), y: 19042.48 }, { x: new Date('2025-07-10'), y: 19048.80 }, { x: new Date('2025-07-12'), y: 18938.93 }, { x: new Date('2025-07-13'), y: 18938.32 }, { x: new Date('2025-07-14'), y: 18970.02 }, { x: new Date('2025-07-16'), y: 18939.47 }, { x: new Date('2025-07-17'), y: 18939.51 }, { x: new Date('2025-07-19'), y: 18972.81 }, { x: new Date('2025-07-20'), y: 18969.49 }, { x: new Date('2025-07-21'), y: 18958.08 }, { x: new Date('2025-07-22'), y: 19047.58 }, { x: new Date('2025-07-23'), y: 19089.86 }, { x: new Date('2025-07-24'), y: 19107.90 }, { x: new Date('2025-07-25'), y: 19133.39 }, { x: new Date('2025-07-26'), y: 19149.58 }, { x: new Date('2025-07-27'), y: 19151.89 }, { x: new Date('2025-07-29'), y: 18986.90 }, { x: new Date('2025-07-30'), y: 18933.04 }, { x: new Date('2025-07-31'), y: 18842.34 }, { x: new Date('2025-08-01'), y: 18837.56 }, { x: new Date('2025-08-02'), y: 18953.22 }, { x: new Date('2025-08-03'), y: 18926.16 }, { x: new Date('2025-08-04'), y: 19007.13 }, { x: new Date('2025-08-05'), y: 18956.88 }, { x: new Date('2025-08-06'), y: 18948.72 }, { x: new Date('2025-08-07'), y: 19026.89 }, { x: new Date('2025-08-08'), y: 19025.12 }, { x: new Date('2025-08-09'), y: 19003.05 }, { x: new Date('2025-08-10'), y: 18987.85 }, { x: new Date('2025-08-11'), y: 18963.82 }, { x: new Date('2025-08-12'), y: 18877.91 }, { x: new Date('2025-08-13'), y: 18943.27 }, { x: new Date('2025-08-14'), y: 18946.33 }, { x: new Date('2025-08-15'), y: 18794.73 }, { x: new Date('2025-08-16'), y: 18859.33 }, { x: new Date('2025-08-18'), y: 18904.11 }, { x: new Date('2025-08-19'), y: 18874.54 }, { x: new Date('2025-08-20'), y: 18965.67 }, { x: new Date('2025-08-21'), y: 18975.93 }, { x: new Date('2025-08-22'), y: 18967.93 }, { x: new Date('2025-08-23'), y: 19060.52 }, { x: new Date('2025-08-24'), y: 19042.92 }, { x: new Date('2025-08-25'), y: 19092.46 }, { x: new Date('2025-08-26'), y: 18962.99 }, { x: new Date('2025-08-27'), y: 18977.24 }, { x: new Date('2025-08-28'), y: 19055.15 }, { x: new Date('2025-08-29'), y: 19083.70 }, { x: new Date('2025-08-30'), y: 19284.86 }, { x: new Date('2025-08-31'), y: 19266.97 }]; 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);