const fullData = [ { x: new Date('2025-04-09'), y: 9454.55 }, { x: new Date('2025-04-10'), y: 9453.67 }, { x: new Date('2025-04-11'), y: 9667.57 }, { x: new Date('2025-04-12'), y: 9769.17 }, { x: new Date('2025-04-13'), y: 9768.12 }, { x: new Date('2025-04-14'), y: 9799.67 }, { x: new Date('2025-04-15'), y: 9846.66 }, { x: new Date('2025-04-16'), y: 9939.21 }, { x: new Date('2025-04-17'), y: 9963.48 }, { x: new Date('2025-04-18'), y: 10065.11 }, { x: new Date('2025-04-19'), y: 10006.38 }, { x: new Date('2025-04-20'), y: 10002.60 }, { x: new Date('2025-04-21'), y: 10036.51 }, { x: new Date('2025-04-22'), y: 10104.64 }, { x: new Date('2025-04-23'), y: 10075.79 }, { x: new Date('2025-04-24'), y: 10070.60 }, { x: new Date('2025-04-26'), y: 10047.82 }, { x: new Date('2025-04-27'), y: 10047.33 }, { x: new Date('2025-04-28'), y: 10022.63 }, { x: new Date('2025-05-02'), y: 9829.25 }, { x: new Date('2025-05-05'), y: 9808.21 }, { x: new Date('2025-05-06'), y: 9808.21 }, { x: new Date('2025-05-08'), y: 9865.24 }, { x: new Date('2025-05-09'), y: 9773.44 }, { x: new Date('2025-05-10'), y: 9780.90 }, { x: new Date('2025-05-11'), y: 9773.63 }, { x: new Date('2025-05-12'), y: 9796.21 }, { x: new Date('2025-05-13'), y: 9732.85 }, { x: new Date('2025-05-14'), y: 9811.19 }, { x: new Date('2025-05-15'), y: 9799.82 }, { x: new Date('2025-05-16'), y: 9699.03 }, { x: new Date('2025-05-17'), y: 9690.44 }, { x: new Date('2025-05-19'), y: 9703.15 }, { x: new Date('2025-05-20'), y: 9743.29 }, { x: new Date('2025-05-21'), y: 9719.22 }, { x: new Date('2025-05-22'), y: 9733.98 }, { x: new Date('2025-05-24'), y: 9697.17 }, { x: new Date('2025-05-26'), y: 9723.66 }, { x: new Date('2025-05-27'), y: 9754.80 }, { x: new Date('2025-06-04'), y: 9797.29 }, { x: new Date('2025-06-05'), y: 9820.97 }, { x: new Date('2025-06-06'), y: 9830.20 }, { x: new Date('2025-06-07'), y: 9813.27 }, { x: new Date('2025-06-08'), y: 9813.53 }, { x: new Date('2025-06-10'), y: 9853.50 }, { x: new Date('2025-06-11'), y: 9848.82 }, { x: new Date('2025-06-12'), y: 9818.92 }, { x: new Date('2025-06-13'), y: 9833.98 }, { x: new Date('2025-06-14'), y: 9822.97 }, { x: new Date('2025-06-15'), y: 9818.99 }, { x: new Date('2025-06-16'), y: 9800.73 }, { x: new Date('2025-06-17'), y: 9870.98 }, { x: new Date('2025-06-18'), y: 9828.59 }, { x: new Date('2025-06-20'), y: 9814.57 }, { x: new Date('2025-06-21'), y: 9797.54 }, { x: new Date('2025-06-22'), y: 9799.84 }, { x: new Date('2025-06-23'), y: 9779.32 }, { x: new Date('2025-06-24'), y: 9806.28 }, { x: new Date('2025-06-25'), y: 9821.39 }, { x: new Date('2025-06-26'), y: 9847.94 }, { x: new Date('2025-06-27'), y: 9827.49 }, { x: new Date('2025-06-28'), y: 9835.91 }, { x: new Date('2025-06-29'), y: 9835.35 }, { x: new Date('2025-06-30'), y: 9837.63 }, { x: new Date('2025-07-01'), y: 9861.47 }, { x: new Date('2025-07-02'), y: 9890.40 }, { x: new Date('2025-07-04'), y: 9837.90 }, { x: new Date('2025-07-05'), y: 9814.31 }, { x: new Date('2025-07-06'), y: 9814.49 }, { x: new Date('2025-07-07'), y: 9804.85 }, { x: new Date('2025-07-08'), y: 9757.26 }, { x: new Date('2025-07-09'), y: 9758.11 }, { x: new Date('2025-07-10'), y: 9753.02 }, { x: new Date('2025-07-12'), y: 9756.47 }, { x: new Date('2025-07-13'), y: 9753.84 }, { x: new Date('2025-07-14'), y: 9747.44 }, { x: new Date('2025-07-16'), y: 9705.56 }, { x: new Date('2025-07-17'), y: 9691.28 }, { x: new Date('2025-07-19'), y: 9739.66 }, { x: new Date('2025-07-20'), y: 9742.64 }, { x: new Date('2025-07-21'), y: 9711.94 }, { x: new Date('2025-07-22'), y: 9740.31 }, { x: new Date('2025-07-23'), y: 9751.81 }, { x: new Date('2025-07-24'), y: 9834.02 }, { x: new Date('2025-07-25'), y: 9836.65 }, { x: new Date('2025-07-26'), y: 9825.56 }, { x: new Date('2025-07-27'), y: 9823.45 }, { x: new Date('2025-07-29'), y: 9779.88 }, { x: new Date('2025-07-30'), y: 9758.99 }, { x: new Date('2025-07-31'), y: 9724.46 }, { x: new Date('2025-08-01'), y: 9719.20 }, { x: new Date('2025-08-02'), y: 9702.38 }, { x: new Date('2025-08-03'), y: 9699.90 }, { x: new Date('2025-08-04'), y: 9709.25 }, { x: new Date('2025-08-05'), y: 9690.08 }, { x: new Date('2025-08-06'), y: 9674.49 }, { x: new Date('2025-08-07'), y: 9702.79 }, { x: new Date('2025-08-08'), y: 9722.53 }, { x: new Date('2025-08-09'), y: 9705.47 }, { x: new Date('2025-08-10'), y: 9702.32 }, { x: new Date('2025-08-11'), y: 9686.67 }, { x: new Date('2025-08-12'), y: 9665.20 }, { x: new Date('2025-08-13'), y: 9668.48 }, { x: new Date('2025-08-14'), y: 9661.50 }, { x: new Date('2025-08-15'), y: 9571.99 }, { x: new Date('2025-08-16'), y: 9603.19 }, { x: new Date('2025-08-18'), y: 9592.75 }, { x: new Date('2025-08-19'), y: 9602.91 }, { x: new Date('2025-08-20'), y: 9608.24 }, { x: new Date('2025-08-21'), y: 9487.50 }, { x: new Date('2025-08-22'), y: 9504.68 }, { x: new Date('2025-08-23'), y: 9537.71 }, { x: new Date('2025-08-24'), y: 9532.39 }, { x: new Date('2025-08-25'), y: 9542.93 }, { x: new Date('2025-08-26'), y: 9528.09 }, { x: new Date('2025-08-27'), y: 9549.05 }, { x: new Date('2025-08-28'), y: 9588.28 }, { x: new Date('2025-08-29'), y: 9614.94 }, { x: new Date('2025-08-30'), y: 9717.19 }, { x: new Date('2025-08-31'), y: 9714.02 }]; 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);