const fullData = [ { x: new Date('2025-04-09'), y: 11886.01 }, { x: new Date('2025-04-10'), y: 11924.29 }, { x: new Date('2025-04-11'), y: 12009.93 }, { x: new Date('2025-04-12'), y: 12085.71 }, { x: new Date('2025-04-13'), y: 12094.27 }, { x: new Date('2025-04-14'), y: 12105.66 }, { x: new Date('2025-04-15'), y: 12076.38 }, { x: new Date('2025-04-16'), y: 12082.23 }, { x: new Date('2025-04-17'), y: 12090.97 }, { x: new Date('2025-04-18'), y: 12162.75 }, { x: new Date('2025-04-19'), y: 12148.86 }, { x: new Date('2025-04-20'), y: 12149.93 }, { x: new Date('2025-04-21'), y: 12171.87 }, { x: new Date('2025-04-22'), y: 12171.32 }, { x: new Date('2025-04-23'), y: 12185.69 }, { x: new Date('2025-04-24'), y: 12183.76 }, { x: new Date('2025-04-26'), y: 12154.52 }, { x: new Date('2025-04-27'), y: 12153.76 }, { x: new Date('2025-04-28'), y: 12143.24 }, { x: new Date('2025-05-02'), y: 12015.55 }, { x: new Date('2025-05-05'), y: 11898.78 }, { x: new Date('2025-05-06'), y: 11898.78 }, { x: new Date('2025-05-08'), y: 11918.20 }, { x: new Date('2025-05-09'), y: 11879.30 }, { x: new Date('2025-05-10'), y: 11882.67 }, { x: new Date('2025-05-11'), y: 11880.01 }, { x: new Date('2025-05-12'), y: 11872.89 }, { x: new Date('2025-05-13'), y: 11823.58 }, { x: new Date('2025-05-14'), y: 11818.41 }, { x: new Date('2025-05-15'), y: 11873.71 }, { x: new Date('2025-05-16'), y: 11803.48 }, { x: new Date('2025-05-17'), y: 11766.78 }, { x: new Date('2025-05-19'), y: 11784.13 }, { x: new Date('2025-05-20'), y: 11781.82 }, { x: new Date('2025-05-21'), y: 11780.23 }, { x: new Date('2025-05-22'), y: 11783.78 }, { x: new Date('2025-05-24'), y: 11777.00 }, { x: new Date('2025-05-26'), y: 11750.51 }, { x: new Date('2025-05-27'), y: 11803.86 }, { x: new Date('2025-06-04'), y: 11883.89 }, { x: new Date('2025-06-05'), y: 11902.19 }, { x: new Date('2025-06-06'), y: 11907.20 }, { x: new Date('2025-06-07'), y: 11896.63 }, { x: new Date('2025-06-08'), y: 11897.37 }, { x: new Date('2025-06-10'), y: 11894.19 }, { x: new Date('2025-06-11'), y: 11892.79 }, { x: new Date('2025-06-12'), y: 11896.93 }, { x: new Date('2025-06-13'), y: 11911.50 }, { x: new Date('2025-06-14'), y: 12003.89 }, { x: new Date('2025-06-15'), y: 11993.42 }, { x: new Date('2025-06-16'), y: 11989.26 }, { x: new Date('2025-06-17'), y: 12009.44 }, { x: new Date('2025-06-18'), y: 11927.87 }, { x: new Date('2025-06-20'), y: 11940.51 }, { x: new Date('2025-06-21'), y: 11937.41 }, { x: new Date('2025-06-22'), y: 11939.95 }, { x: new Date('2025-06-23'), y: 11935.41 }, { x: new Date('2025-06-24'), y: 12005.33 }, { x: new Date('2025-06-25'), y: 11910.11 }, { x: new Date('2025-06-26'), y: 11885.25 }, { x: new Date('2025-06-27'), y: 11878.23 }, { x: new Date('2025-06-28'), y: 11869.27 }, { x: new Date('2025-06-29'), y: 11868.70 }, { x: new Date('2025-06-30'), y: 11856.60 }, { x: new Date('2025-07-01'), y: 11897.92 }, { x: new Date('2025-07-02'), y: 11889.01 }, { x: new Date('2025-07-04'), y: 11921.63 }, { x: new Date('2025-07-05'), y: 11905.75 }, { x: new Date('2025-07-06'), y: 11907.35 }, { x: new Date('2025-07-07'), y: 11899.60 }, { x: new Date('2025-07-08'), y: 11887.38 }, { x: new Date('2025-07-09'), y: 11888.34 }, { x: new Date('2025-07-10'), y: 11877.51 }, { x: new Date('2025-07-12'), y: 11862.97 }, { x: new Date('2025-07-13'), y: 11854.67 }, { x: new Date('2025-07-14'), y: 11854.80 }, { x: new Date('2025-07-16'), y: 11876.78 }, { x: new Date('2025-07-17'), y: 11887.43 }, { x: new Date('2025-07-19'), y: 11882.83 }, { x: new Date('2025-07-20'), y: 11879.88 }, { x: new Date('2025-07-21'), y: 11871.28 }, { x: new Date('2025-07-22'), y: 11908.86 }, { x: new Date('2025-07-23'), y: 11940.93 }, { x: new Date('2025-07-24'), y: 11960.93 }, { x: new Date('2025-07-25'), y: 11940.19 }, { x: new Date('2025-07-26'), y: 11915.74 }, { x: new Date('2025-07-27'), y: 11921.32 }, { x: new Date('2025-07-29'), y: 11907.88 }, { x: new Date('2025-07-30'), y: 11910.56 }, { x: new Date('2025-07-31'), y: 11886.16 }, { x: new Date('2025-08-01'), y: 11900.04 }, { x: new Date('2025-08-02'), y: 11917.40 }, { x: new Date('2025-08-03'), y: 11913.53 }, { x: new Date('2025-08-04'), y: 11940.73 }, { x: new Date('2025-08-05'), y: 11891.36 }, { x: new Date('2025-08-06'), y: 11890.14 }, { x: new Date('2025-08-07'), y: 11897.76 }, { x: new Date('2025-08-08'), y: 11877.18 }, { x: new Date('2025-08-09'), y: 11867.62 }, { x: new Date('2025-08-10'), y: 11861.80 }, { x: new Date('2025-08-11'), y: 11842.74 }, { x: new Date('2025-08-12'), y: 11801.74 }, { x: new Date('2025-08-13'), y: 11802.82 }, { x: new Date('2025-08-14'), y: 11742.68 }, { x: new Date('2025-08-15'), y: 11676.43 }, { x: new Date('2025-08-16'), y: 11686.99 }, { x: new Date('2025-08-18'), y: 11699.84 }, { x: new Date('2025-08-19'), y: 11737.85 }, { x: new Date('2025-08-20'), y: 11748.18 }, { x: new Date('2025-08-21'), y: 11741.54 }, { x: new Date('2025-08-22'), y: 11741.84 }, { x: new Date('2025-08-23'), y: 11778.54 }, { x: new Date('2025-08-24'), y: 11774.67 }, { x: new Date('2025-08-25'), y: 11798.60 }, { x: new Date('2025-08-26'), y: 11748.83 }, { x: new Date('2025-08-27'), y: 11775.15 }, { x: new Date('2025-08-28'), y: 11871.25 }, { x: new Date('2025-08-29'), y: 11882.64 }, { x: new Date('2025-08-30'), y: 12012.48 }, { x: new Date('2025-08-31'), y: 12003.91 }]; 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);