const fullData = [ { x: new Date('2025-04-09'), y: 295.11 }, { x: new Date('2025-04-10'), y: 294.46 }, { x: new Date('2025-04-11'), y: 293.57 }, { x: new Date('2025-04-12'), y: 295.22 }, { x: new Date('2025-04-13'), y: 295.15 }, { x: new Date('2025-04-14'), y: 294.99 }, { x: new Date('2025-04-15'), y: 294.37 }, { x: new Date('2025-04-16'), y: 296.34 }, { x: new Date('2025-04-17'), y: 296.87 }, { x: new Date('2025-04-18'), y: 297.11 }, { x: new Date('2025-04-19'), y: 297.09 }, { x: new Date('2025-04-20'), y: 297.03 }, { x: new Date('2025-04-21'), y: 297.19 }, { x: new Date('2025-04-22'), y: 297.17 }, { x: new Date('2025-04-23'), y: 298.04 }, { x: new Date('2025-04-24'), y: 298.23 }, { x: new Date('2025-04-26'), y: 299.26 }, { x: new Date('2025-04-27'), y: 299.29 }, { x: new Date('2025-04-28'), y: 299.30 }, { x: new Date('2025-05-02'), y: 297.35 }, { x: new Date('2025-05-05'), y: 295.97 }, { x: new Date('2025-05-06'), y: 295.97 }, { x: new Date('2025-05-08'), y: 296.43 }, { x: new Date('2025-05-09'), y: 296.65 }, { x: new Date('2025-05-10'), y: 298.45 }, { x: new Date('2025-05-11'), y: 298.28 }, { x: new Date('2025-05-12'), y: 298.54 }, { x: new Date('2025-05-13'), y: 298.24 }, { x: new Date('2025-05-14'), y: 297.26 }, { x: new Date('2025-05-15'), y: 296.35 }, { x: new Date('2025-05-16'), y: 296.15 }, { x: new Date('2025-05-17'), y: 295.22 }, { x: new Date('2025-05-19'), y: 295.18 }, { x: new Date('2025-05-20'), y: 294.98 }, { x: new Date('2025-05-21'), y: 294.85 }, { x: new Date('2025-05-22'), y: 294.03 }, { x: new Date('2025-05-24'), y: 293.43 }, { x: new Date('2025-05-26'), y: 293.24 }, { x: new Date('2025-05-27'), y: 293.16 }, { x: new Date('2025-06-04'), y: 293.00 }, { x: new Date('2025-06-05'), y: 292.35 }, { x: new Date('2025-06-06'), y: 292.35 }, { x: new Date('2025-06-07'), y: 292.19 }, { x: new Date('2025-06-08'), y: 292.16 }, { x: new Date('2025-06-10'), y: 291.78 }, { x: new Date('2025-06-11'), y: 291.23 }, { x: new Date('2025-06-12'), y: 291.13 }, { x: new Date('2025-06-13'), y: 291.28 }, { x: new Date('2025-06-14'), y: 289.83 }, { x: new Date('2025-06-15'), y: 289.86 }, { x: new Date('2025-06-16'), y: 289.85 }, { x: new Date('2025-06-17'), y: 288.84 }, { x: new Date('2025-06-18'), y: 287.58 }, { x: new Date('2025-06-20'), y: 285.87 }, { x: new Date('2025-06-21'), y: 286.62 }, { x: new Date('2025-06-22'), y: 286.67 }, { x: new Date('2025-06-23'), y: 286.79 }, { x: new Date('2025-06-24'), y: 286.65 }, { x: new Date('2025-06-25'), y: 286.19 }, { x: new Date('2025-06-26'), y: 287.34 }, { x: new Date('2025-06-27'), y: 286.19 }, { x: new Date('2025-06-28'), y: 286.76 }, { x: new Date('2025-06-29'), y: 286.80 }, { x: new Date('2025-06-30'), y: 286.78 }, { x: new Date('2025-07-01'), y: 287.52 }, { x: new Date('2025-07-02'), y: 287.80 }, { x: new Date('2025-07-04'), y: 287.70 }, { x: new Date('2025-07-05'), y: 286.84 }, { x: new Date('2025-07-06'), y: 286.82 }, { x: new Date('2025-07-07'), y: 286.79 }, { x: new Date('2025-07-08'), y: 286.88 }, { x: new Date('2025-07-09'), y: 287.46 }, { x: new Date('2025-07-10'), y: 287.21 }, { x: new Date('2025-07-12'), y: 287.00 }, { x: new Date('2025-07-13'), y: 287.12 }, { x: new Date('2025-07-14'), y: 287.22 }, { x: new Date('2025-07-16'), y: 286.37 }, { x: new Date('2025-07-17'), y: 285.77 }, { x: new Date('2025-07-19'), y: 285.50 }, { x: new Date('2025-07-20'), y: 285.87 }, { x: new Date('2025-07-21'), y: 285.69 }, { x: new Date('2025-07-22'), y: 285.83 }, { x: new Date('2025-07-23'), y: 286.33 }, { x: new Date('2025-07-24'), y: 286.94 }, { x: new Date('2025-07-25'), y: 287.04 }, { x: new Date('2025-07-26'), y: 286.02 }, { x: new Date('2025-07-27'), y: 285.96 }, { x: new Date('2025-07-29'), y: 286.35 }, { x: new Date('2025-07-30'), y: 285.82 }, { x: new Date('2025-07-31'), y: 284.25 }, { x: new Date('2025-08-01'), y: 282.74 }, { x: new Date('2025-08-02'), y: 283.22 }, { x: new Date('2025-08-03'), y: 283.33 }, { x: new Date('2025-08-04'), y: 284.23 }, { x: new Date('2025-08-05'), y: 285.60 }, { x: new Date('2025-08-06'), y: 284.62 }, { x: new Date('2025-08-07'), y: 285.06 }, { x: new Date('2025-08-08'), y: 285.39 }, { x: new Date('2025-08-09'), y: 286.08 }, { x: new Date('2025-08-10'), y: 285.97 }, { x: new Date('2025-08-11'), y: 286.12 }, { x: new Date('2025-08-12'), y: 285.33 }, { x: new Date('2025-08-13'), y: 285.83 }, { x: new Date('2025-08-14'), y: 284.44 }, { x: new Date('2025-08-15'), y: 283.04 }, { x: new Date('2025-08-16'), y: 283.09 }, { x: new Date('2025-08-18'), y: 283.33 }, { x: new Date('2025-08-19'), y: 284.02 }, { x: new Date('2025-08-20'), y: 284.43 }, { x: new Date('2025-08-21'), y: 285.29 }, { x: new Date('2025-08-22'), y: 285.56 }, { x: new Date('2025-08-23'), y: 287.59 }, { x: new Date('2025-08-24'), y: 287.49 }, { x: new Date('2025-08-25'), y: 288.14 }, { x: new Date('2025-08-26'), y: 286.63 }, { x: new Date('2025-08-27'), y: 286.20 }, { x: new Date('2025-08-28'), y: 286.15 }, { x: new Date('2025-08-29'), y: 286.94 }, { x: new Date('2025-08-30'), y: 287.63 }, { x: new Date('2025-08-31'), y: 287.74 }]; 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);