const fullData = [ { x: new Date('2025-04-09'), y: 12494.78 }, { x: new Date('2025-04-10'), y: 12547.48 }, { x: new Date('2025-04-11'), y: 12626.41 }, { x: new Date('2025-04-12'), y: 12720.17 }, { x: new Date('2025-04-13'), y: 12729.20 }, { x: new Date('2025-04-14'), y: 12738.42 }, { x: new Date('2025-04-15'), y: 12741.15 }, { x: new Date('2025-04-16'), y: 12762.94 }, { x: new Date('2025-04-17'), y: 12792.31 }, { x: new Date('2025-04-18'), y: 12852.21 }, { x: new Date('2025-04-19'), y: 12841.23 }, { x: new Date('2025-04-20'), y: 12842.38 }, { x: new Date('2025-04-21'), y: 12849.69 }, { x: new Date('2025-04-22'), y: 12901.22 }, { x: new Date('2025-04-23'), y: 12862.92 }, { x: new Date('2025-04-24'), y: 12852.18 }, { x: new Date('2025-04-26'), y: 12825.08 }, { x: new Date('2025-04-27'), y: 12823.99 }, { x: new Date('2025-04-28'), y: 12807.17 }, { x: new Date('2025-05-02'), y: 12692.22 }, { x: new Date('2025-05-05'), y: 12674.55 }, { x: new Date('2025-05-06'), y: 12674.55 }, { x: new Date('2025-05-08'), y: 12746.60 }, { x: new Date('2025-05-09'), y: 12719.59 }, { x: new Date('2025-05-10'), y: 12750.43 }, { x: new Date('2025-05-11'), y: 12744.82 }, { x: new Date('2025-05-12'), y: 12739.56 }, { x: new Date('2025-05-13'), y: 12656.12 }, { x: new Date('2025-05-14'), y: 12662.61 }, { x: new Date('2025-05-15'), y: 12752.90 }, { x: new Date('2025-05-16'), y: 12712.54 }, { x: new Date('2025-05-17'), y: 12657.89 }, { x: new Date('2025-05-19'), y: 12665.21 }, { x: new Date('2025-05-20'), y: 12694.43 }, { x: new Date('2025-05-21'), y: 12669.03 }, { x: new Date('2025-05-22'), y: 12724.32 }, { x: new Date('2025-05-24'), y: 12614.34 }, { x: new Date('2025-05-26'), y: 12623.71 }, { x: new Date('2025-05-27'), y: 12621.25 }, { x: new Date('2025-06-04'), y: 12650.43 }, { x: new Date('2025-06-05'), y: 12659.39 }, { x: new Date('2025-06-06'), y: 12654.37 }, { x: new Date('2025-06-07'), y: 12645.41 }, { x: new Date('2025-06-08'), y: 12649.20 }, { x: new Date('2025-06-10'), y: 12662.71 }, { x: new Date('2025-06-11'), y: 12650.13 }, { x: new Date('2025-06-12'), y: 12656.18 }, { x: new Date('2025-06-13'), y: 12684.64 }, { x: new Date('2025-06-14'), y: 12736.23 }, { x: new Date('2025-06-15'), y: 12727.67 }, { x: new Date('2025-06-16'), y: 12705.60 }, { x: new Date('2025-06-17'), y: 12730.41 }, { x: new Date('2025-06-18'), y: 12646.23 }, { x: new Date('2025-06-20'), y: 12716.51 }, { x: new Date('2025-06-21'), y: 12734.90 }, { x: new Date('2025-06-22'), y: 12738.14 }, { x: new Date('2025-06-23'), y: 12721.18 }, { x: new Date('2025-06-24'), y: 12824.11 }, { x: new Date('2025-06-25'), y: 12760.94 }, { x: new Date('2025-06-26'), y: 12753.73 }, { x: new Date('2025-06-27'), y: 12727.51 }, { x: new Date('2025-06-28'), y: 12720.46 }, { x: new Date('2025-06-29'), y: 12714.60 }, { x: new Date('2025-06-30'), y: 12707.37 }, { x: new Date('2025-07-01'), y: 12751.37 }, { x: new Date('2025-07-02'), y: 12739.33 }, { x: new Date('2025-07-04'), y: 12703.09 }, { x: new Date('2025-07-05'), y: 12706.97 }, { x: new Date('2025-07-06'), y: 12707.20 }, { x: new Date('2025-07-07'), y: 12703.32 }, { x: new Date('2025-07-08'), y: 12701.69 }, { x: new Date('2025-07-09'), y: 12698.07 }, { x: new Date('2025-07-10'), y: 12699.83 }, { x: new Date('2025-07-12'), y: 12682.49 }, { x: new Date('2025-07-13'), y: 12675.23 }, { x: new Date('2025-07-14'), y: 12675.33 }, { x: new Date('2025-07-16'), y: 12684.09 }, { x: new Date('2025-07-17'), y: 12687.58 }, { x: new Date('2025-07-19'), y: 12698.21 }, { x: new Date('2025-07-20'), y: 12696.32 }, { x: new Date('2025-07-21'), y: 12690.38 }, { x: new Date('2025-07-22'), y: 12731.41 }, { x: new Date('2025-07-23'), y: 12725.78 }, { x: new Date('2025-07-24'), y: 12732.67 }, { x: new Date('2025-07-25'), y: 12740.71 }, { x: new Date('2025-07-26'), y: 12740.09 }, { x: new Date('2025-07-27'), y: 12742.18 }, { x: new Date('2025-07-29'), y: 12720.43 }, { x: new Date('2025-07-30'), y: 12728.90 }, { x: new Date('2025-07-31'), y: 12695.75 }, { x: new Date('2025-08-01'), y: 12698.09 }, { x: new Date('2025-08-02'), y: 12739.00 }, { x: new Date('2025-08-03'), y: 12732.87 }, { x: new Date('2025-08-04'), y: 12761.03 }, { x: new Date('2025-08-05'), y: 12726.96 }, { x: new Date('2025-08-06'), y: 12722.70 }, { x: new Date('2025-08-07'), y: 12725.21 }, { x: new Date('2025-08-08'), y: 12711.62 }, { x: new Date('2025-08-09'), y: 12696.46 }, { x: new Date('2025-08-10'), y: 12688.15 }, { x: new Date('2025-08-11'), y: 12673.40 }, { x: new Date('2025-08-12'), y: 12643.11 }, { x: new Date('2025-08-13'), y: 12666.28 }, { x: new Date('2025-08-14'), y: 12635.99 }, { x: new Date('2025-08-15'), y: 12558.46 }, { x: new Date('2025-08-16'), y: 12576.44 }, { x: new Date('2025-08-18'), y: 12598.91 }, { x: new Date('2025-08-19'), y: 12623.29 }, { x: new Date('2025-08-20'), y: 12660.35 }, { x: new Date('2025-08-21'), y: 12671.77 }, { x: new Date('2025-08-22'), y: 12662.80 }, { x: new Date('2025-08-23'), y: 12714.28 }, { x: new Date('2025-08-24'), y: 12709.84 }, { x: new Date('2025-08-25'), y: 12731.59 }, { x: new Date('2025-08-26'), y: 12659.14 }, { x: new Date('2025-08-27'), y: 12676.33 }, { x: new Date('2025-08-28'), y: 12744.08 }, { x: new Date('2025-08-29'), y: 12740.74 }, { x: new Date('2025-08-30'), y: 12855.53 }, { x: new Date('2025-08-31'), y: 12845.66 }]; 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);