const fullData = [ { x: new Date('2025-04-09'), y: 55269.64 }, { x: new Date('2025-04-10'), y: 55131.74 }, { x: new Date('2025-04-11'), y: 55147.15 }, { x: new Date('2025-04-12'), y: 54995.79 }, { x: new Date('2025-04-13'), y: 55120.35 }, { x: new Date('2025-04-14'), y: 55031.42 }, { x: new Date('2025-04-15'), y: 55187.19 }, { x: new Date('2025-04-16'), y: 55245.52 }, { x: new Date('2025-04-17'), y: 55105.15 }, { x: new Date('2025-04-18'), y: 55208.08 }, { x: new Date('2025-04-19'), y: 55192.89 }, { x: new Date('2025-04-20'), y: 55257.80 }, { x: new Date('2025-04-21'), y: 55151.79 }, { x: new Date('2025-04-22'), y: 55099.75 }, { x: new Date('2025-04-23'), y: 55269.29 }, { x: new Date('2025-04-24'), y: 55345.94 }, { x: new Date('2025-04-26'), y: 55299.14 }, { x: new Date('2025-04-27'), y: 55327.72 }, { x: new Date('2025-04-28'), y: 55256.42 }, { x: new Date('2025-05-02'), y: 54638.74 }, { x: new Date('2025-05-05'), y: 53279.41 }, { x: new Date('2025-05-06'), y: 53279.41 }, { x: new Date('2025-05-08'), y: 53241.06 }, { x: new Date('2025-05-09'), y: 53451.54 }, { x: new Date('2025-05-10'), y: 53457.28 }, { x: new Date('2025-05-11'), y: 53300.92 }, { x: new Date('2025-05-12'), y: 53395.96 }, { x: new Date('2025-05-13'), y: 53565.10 }, { x: new Date('2025-05-14'), y: 53719.40 }, { x: new Date('2025-05-15'), y: 53322.82 }, { x: new Date('2025-05-16'), y: 53281.25 }, { x: new Date('2025-05-17'), y: 53463.84 }, { x: new Date('2025-05-19'), y: 53285.00 }, { x: new Date('2025-05-20'), y: 53185.24 }, { x: new Date('2025-05-21'), y: 53215.98 }, { x: new Date('2025-05-22'), y: 53063.24 }, { x: new Date('2025-05-24'), y: 53069.32 }, { x: new Date('2025-05-26'), y: 52881.02 }, { x: new Date('2025-05-27'), y: 52928.60 }, { x: new Date('2025-06-04'), y: 53052.14 }, { x: new Date('2025-06-05'), y: 53048.18 }, { x: new Date('2025-06-06'), y: 53114.47 }, { x: new Date('2025-06-07'), y: 52843.21 }, { x: new Date('2025-06-08'), y: 52845.61 }, { x: new Date('2025-06-10'), y: 53146.97 }, { x: new Date('2025-06-11'), y: 53032.55 }, { x: new Date('2025-06-12'), y: 53005.95 }, { x: new Date('2025-06-13'), y: 52956.55 }, { x: new Date('2025-06-14'), y: 53142.53 }, { x: new Date('2025-06-15'), y: 53017.02 }, { x: new Date('2025-06-16'), y: 53056.87 }, { x: new Date('2025-06-17'), y: 53013.05 }, { x: new Date('2025-06-18'), y: 53098.41 }, { x: new Date('2025-06-20'), y: 53151.17 }, { x: new Date('2025-06-21'), y: 53216.88 }, { x: new Date('2025-06-22'), y: 53101.63 }, { x: new Date('2025-06-23'), y: 53225.74 }, { x: new Date('2025-06-24'), y: 53589.17 }, { x: new Date('2025-06-25'), y: 53415.08 }, { x: new Date('2025-06-26'), y: 53325.71 }, { x: new Date('2025-06-27'), y: 52976.20 }, { x: new Date('2025-06-28'), y: 53039.85 }, { x: new Date('2025-06-29'), y: 53004.30 }, { x: new Date('2025-06-30'), y: 52918.91 }, { x: new Date('2025-07-01'), y: 53177.55 }, { x: new Date('2025-07-02'), y: 52948.74 }, { x: new Date('2025-07-04'), y: 52995.64 }, { x: new Date('2025-07-05'), y: 53044.53 }, { x: new Date('2025-07-06'), y: 52987.22 }, { x: new Date('2025-07-07'), y: 52965.24 }, { x: new Date('2025-07-08'), y: 53095.70 }, { x: new Date('2025-07-09'), y: 53105.66 }, { x: new Date('2025-07-10'), y: 53075.75 }, { x: new Date('2025-07-12'), y: 53134.61 }, { x: new Date('2025-07-13'), y: 53046.73 }, { x: new Date('2025-07-14'), y: 53017.09 }, { x: new Date('2025-07-16'), y: 53151.58 }, { x: new Date('2025-07-17'), y: 53144.90 }, { x: new Date('2025-07-19'), y: 53330.42 }, { x: new Date('2025-07-20'), y: 53232.00 }, { x: new Date('2025-07-21'), y: 53265.99 }, { x: new Date('2025-07-22'), y: 53231.77 }, { x: new Date('2025-07-23'), y: 53432.54 }, { x: new Date('2025-07-24'), y: 53377.61 }, { x: new Date('2025-07-25'), y: 53176.95 }, { x: new Date('2025-07-26'), y: 53310.30 }, { x: new Date('2025-07-27'), y: 53218.46 }, { x: new Date('2025-07-29'), y: 53376.79 }, { x: new Date('2025-07-30'), y: 53359.48 }, { x: new Date('2025-07-31'), y: 53551.89 }, { x: new Date('2025-08-01'), y: 53657.30 }, { x: new Date('2025-08-02'), y: 53520.97 }, { x: new Date('2025-08-03'), y: 53437.56 }, { x: new Date('2025-08-04'), y: 54147.34 }, { x: new Date('2025-08-05'), y: 53348.50 }, { x: new Date('2025-08-06'), y: 53365.95 }, { x: new Date('2025-08-07'), y: 53317.00 }, { x: new Date('2025-08-08'), y: 53165.52 }, { x: new Date('2025-08-09'), y: 53336.43 }, { x: new Date('2025-08-10'), y: 53217.62 }, { x: new Date('2025-08-11'), y: 53189.92 }, { x: new Date('2025-08-12'), y: 53248.22 }, { x: new Date('2025-08-13'), y: 53195.80 }, { x: new Date('2025-08-14'), y: 52917.01 }, { x: new Date('2025-08-15'), y: 52761.99 }, { x: new Date('2025-08-16'), y: 52737.78 }, { x: new Date('2025-08-18'), y: 53051.12 }, { x: new Date('2025-08-19'), y: 52864.98 }, { x: new Date('2025-08-20'), y: 53168.32 }, { x: new Date('2025-08-21'), y: 53221.92 }, { x: new Date('2025-08-22'), y: 53283.75 }, { x: new Date('2025-08-23'), y: 53167.99 }, { x: new Date('2025-08-24'), y: 53104.25 }, { x: new Date('2025-08-25'), y: 53258.47 }, { x: new Date('2025-08-26'), y: 53200.05 }, { x: new Date('2025-08-27'), y: 53276.43 }, { x: new Date('2025-08-28'), y: 53363.96 }, { x: new Date('2025-08-29'), y: 53270.15 }, { x: new Date('2025-08-30'), y: 53806.41 }, { x: new Date('2025-08-31'), y: 53588.08 }]; 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);