const fullData = [ { x: new Date('2025-04-09'), y: 2478.65 }, { x: new Date('2025-04-10'), y: 2483.63 }, { x: new Date('2025-04-11'), y: 2515.84 }, { x: new Date('2025-04-12'), y: 2549.20 }, { x: new Date('2025-04-13'), y: 2549.65 }, { x: new Date('2025-04-14'), y: 2555.78 }, { x: new Date('2025-04-15'), y: 2551.44 }, { x: new Date('2025-04-16'), y: 2546.02 }, { x: new Date('2025-04-17'), y: 2563.23 }, { x: new Date('2025-04-18'), y: 2566.02 }, { x: new Date('2025-04-19'), y: 2568.83 }, { x: new Date('2025-04-20'), y: 2568.43 }, { x: new Date('2025-04-21'), y: 2577.91 }, { x: new Date('2025-04-22'), y: 2595.45 }, { x: new Date('2025-04-23'), y: 2575.74 }, { x: new Date('2025-04-24'), y: 2567.50 }, { x: new Date('2025-04-26'), y: 2566.10 }, { x: new Date('2025-04-27'), y: 2566.43 }, { x: new Date('2025-04-28'), y: 2561.79 }, { x: new Date('2025-05-02'), y: 2517.41 }, { x: new Date('2025-05-05'), y: 2497.55 }, { x: new Date('2025-05-06'), y: 2497.55 }, { x: new Date('2025-05-08'), y: 2498.30 }, { x: new Date('2025-05-09'), y: 2489.05 }, { x: new Date('2025-05-10'), y: 2496.21 }, { x: new Date('2025-05-11'), y: 2495.32 }, { x: new Date('2025-05-12'), y: 2488.57 }, { x: new Date('2025-05-13'), y: 2455.26 }, { x: new Date('2025-05-14'), y: 2471.45 }, { x: new Date('2025-05-15'), y: 2485.96 }, { x: new Date('2025-05-16'), y: 2475.33 }, { x: new Date('2025-05-17'), y: 2460.60 }, { x: new Date('2025-05-19'), y: 2466.77 }, { x: new Date('2025-05-20'), y: 2476.79 }, { x: new Date('2025-05-21'), y: 2479.79 }, { x: new Date('2025-05-22'), y: 2489.74 }, { x: new Date('2025-05-24'), y: 2465.63 }, { x: new Date('2025-05-26'), y: 2465.23 }, { x: new Date('2025-05-27'), y: 2475.09 }, { x: new Date('2025-06-04'), y: 2486.85 }, { x: new Date('2025-06-05'), y: 2492.38 }, { x: new Date('2025-06-06'), y: 2495.72 }, { x: new Date('2025-06-07'), y: 2492.39 }, { x: new Date('2025-06-08'), y: 2490.75 }, { x: new Date('2025-06-10'), y: 2491.76 }, { x: new Date('2025-06-11'), y: 2492.93 }, { x: new Date('2025-06-12'), y: 2503.96 }, { x: new Date('2025-06-13'), y: 2520.43 }, { x: new Date('2025-06-14'), y: 2524.49 }, { x: new Date('2025-06-15'), y: 2523.23 }, { x: new Date('2025-06-16'), y: 2519.85 }, { x: new Date('2025-06-17'), y: 2524.89 }, { x: new Date('2025-06-18'), y: 2507.54 }, { x: new Date('2025-06-20'), y: 2524.07 }, { x: new Date('2025-06-21'), y: 2529.25 }, { x: new Date('2025-06-22'), y: 2529.23 }, { x: new Date('2025-06-23'), y: 2524.56 }, { x: new Date('2025-06-24'), y: 2557.44 }, { x: new Date('2025-06-25'), y: 2542.98 }, { x: new Date('2025-06-26'), y: 2546.34 }, { x: new Date('2025-06-27'), y: 2543.28 }, { x: new Date('2025-06-28'), y: 2544.63 }, { x: new Date('2025-06-29'), y: 2544.24 }, { x: new Date('2025-06-30'), y: 2547.78 }, { x: new Date('2025-07-01'), y: 2559.56 }, { x: new Date('2025-07-02'), y: 2562.33 }, { x: new Date('2025-07-04'), y: 2553.10 }, { x: new Date('2025-07-05'), y: 2555.28 }, { x: new Date('2025-07-06'), y: 2555.25 }, { x: new Date('2025-07-07'), y: 2554.77 }, { x: new Date('2025-07-08'), y: 2553.14 }, { x: new Date('2025-07-09'), y: 2550.77 }, { x: new Date('2025-07-10'), y: 2552.37 }, { x: new Date('2025-07-12'), y: 2538.81 }, { x: new Date('2025-07-13'), y: 2538.59 }, { x: new Date('2025-07-14'), y: 2542.62 }, { x: new Date('2025-07-16'), y: 2534.67 }, { x: new Date('2025-07-17'), y: 2537.93 }, { x: new Date('2025-07-19'), y: 2542.50 }, { x: new Date('2025-07-20'), y: 2542.55 }, { x: new Date('2025-07-21'), y: 2539.96 }, { x: new Date('2025-07-22'), y: 2554.09 }, { x: new Date('2025-07-23'), y: 2561.56 }, { x: new Date('2025-07-24'), y: 2564.22 }, { x: new Date('2025-07-25'), y: 2565.14 }, { x: new Date('2025-07-26'), y: 2565.72 }, { x: new Date('2025-07-27'), y: 2566.79 }, { x: new Date('2025-07-29'), y: 2542.80 }, { x: new Date('2025-07-30'), y: 2537.62 }, { x: new Date('2025-07-31'), y: 2518.88 }, { x: new Date('2025-08-01'), y: 2522.76 }, { x: new Date('2025-08-02'), y: 2544.66 }, { x: new Date('2025-08-03'), y: 2538.43 }, { x: new Date('2025-08-04'), y: 2551.42 }, { x: new Date('2025-08-05'), y: 2541.87 }, { x: new Date('2025-08-06'), y: 2540.30 }, { x: new Date('2025-08-07'), y: 2552.70 }, { x: new Date('2025-08-08'), y: 2548.91 }, { x: new Date('2025-08-09'), y: 2546.37 }, { x: new Date('2025-08-10'), y: 2545.11 }, { x: new Date('2025-08-11'), y: 2541.96 }, { x: new Date('2025-08-12'), y: 2532.34 }, { x: new Date('2025-08-13'), y: 2542.74 }, { x: new Date('2025-08-14'), y: 2539.77 }, { x: new Date('2025-08-15'), y: 2518.26 }, { x: new Date('2025-08-16'), y: 2524.15 }, { x: new Date('2025-08-18'), y: 2535.10 }, { x: new Date('2025-08-19'), y: 2528.68 }, { x: new Date('2025-08-20'), y: 2538.91 }, { x: new Date('2025-08-21'), y: 2541.98 }, { x: new Date('2025-08-22'), y: 2538.81 }, { x: new Date('2025-08-23'), y: 2558.33 }, { x: new Date('2025-08-24'), y: 2553.76 }, { x: new Date('2025-08-25'), y: 2550.11 }, { x: new Date('2025-08-26'), y: 2537.57 }, { x: new Date('2025-08-27'), y: 2542.93 }, { x: new Date('2025-08-28'), y: 2553.32 }, { x: new Date('2025-08-29'), y: 2557.42 }, { x: new Date('2025-08-30'), y: 2584.62 }, { x: new Date('2025-08-31'), y: 2582.69 }]; 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);