const fullData = [ { x: new Date('2025-04-09'), y: 19872.05 }, { x: new Date('2025-04-10'), y: 19917.25 }, { x: new Date('2025-04-11'), y: 19992.10 }, { x: new Date('2025-04-12'), y: 20481.74 }, { x: new Date('2025-04-13'), y: 20465.41 }, { x: new Date('2025-04-14'), y: 20543.64 }, { x: new Date('2025-04-15'), y: 20507.18 }, { x: new Date('2025-04-16'), y: 20541.97 }, { x: new Date('2025-04-17'), y: 20610.56 }, { x: new Date('2025-04-18'), y: 20590.97 }, { x: new Date('2025-04-19'), y: 20582.41 }, { x: new Date('2025-04-20'), y: 20582.14 }, { x: new Date('2025-04-21'), y: 20688.47 }, { x: new Date('2025-04-22'), y: 20829.03 }, { x: new Date('2025-04-23'), y: 20618.28 }, { x: new Date('2025-04-24'), y: 20436.23 }, { x: new Date('2025-04-26'), y: 20329.62 }, { x: new Date('2025-04-27'), y: 20329.37 }, { x: new Date('2025-04-28'), y: 20325.12 }, { x: new Date('2025-05-02'), y: 20056.10 }, { x: new Date('2025-05-05'), y: 19929.29 }, { x: new Date('2025-05-06'), y: 19929.29 }, { x: new Date('2025-05-08'), y: 19923.33 }, { x: new Date('2025-05-09'), y: 19931.03 }, { x: new Date('2025-05-10'), y: 19914.73 }, { x: new Date('2025-05-11'), y: 19907.88 }, { x: new Date('2025-05-12'), y: 19841.19 }, { x: new Date('2025-05-13'), y: 19546.05 }, { x: new Date('2025-05-14'), y: 19654.03 }, { x: new Date('2025-05-15'), y: 19745.59 }, { x: new Date('2025-05-16'), y: 19720.47 }, { x: new Date('2025-05-17'), y: 19617.61 }, { x: new Date('2025-05-19'), y: 19677.49 }, { x: new Date('2025-05-20'), y: 19700.51 }, { x: new Date('2025-05-21'), y: 19756.44 }, { x: new Date('2025-05-22'), y: 19808.16 }, { x: new Date('2025-05-24'), y: 19712.70 }, { x: new Date('2025-05-26'), y: 19699.99 }, { x: new Date('2025-05-27'), y: 19741.95 }, { x: new Date('2025-06-04'), y: 19832.15 }, { x: new Date('2025-06-05'), y: 19868.03 }, { x: new Date('2025-06-06'), y: 19837.42 }, { x: new Date('2025-06-07'), y: 19808.80 }, { x: new Date('2025-06-08'), y: 19810.26 }, { x: new Date('2025-06-10'), y: 19826.08 }, { x: new Date('2025-06-11'), y: 19799.17 }, { x: new Date('2025-06-12'), y: 19827.55 }, { x: new Date('2025-06-13'), y: 19979.96 }, { x: new Date('2025-06-14'), y: 20113.34 }, { x: new Date('2025-06-15'), y: 20097.50 }, { x: new Date('2025-06-16'), y: 20075.54 }, { x: new Date('2025-06-17'), y: 20053.10 }, { x: new Date('2025-06-18'), y: 19931.97 }, { x: new Date('2025-06-20'), y: 20024.65 }, { x: new Date('2025-06-21'), y: 20041.16 }, { x: new Date('2025-06-22'), y: 20043.20 }, { x: new Date('2025-06-23'), y: 20052.66 }, { x: new Date('2025-06-24'), y: 20262.92 }, { x: new Date('2025-06-25'), y: 20246.98 }, { x: new Date('2025-06-26'), y: 20255.46 }, { x: new Date('2025-06-27'), y: 20265.35 }, { x: new Date('2025-06-28'), y: 20279.73 }, { x: new Date('2025-06-29'), y: 20279.15 }, { x: new Date('2025-06-30'), y: 20290.03 }, { x: new Date('2025-07-01'), y: 20407.89 }, { x: new Date('2025-07-02'), y: 20492.35 }, { x: new Date('2025-07-04'), y: 20367.96 }, { x: new Date('2025-07-05'), y: 20390.64 }, { x: new Date('2025-07-06'), y: 20391.28 }, { x: new Date('2025-07-07'), y: 20378.22 }, { x: new Date('2025-07-08'), y: 20367.26 }, { x: new Date('2025-07-09'), y: 20385.98 }, { x: new Date('2025-07-10'), y: 20449.44 }, { x: new Date('2025-07-12'), y: 20381.23 }, { x: new Date('2025-07-13'), y: 20368.96 }, { x: new Date('2025-07-14'), y: 20369.12 }, { x: new Date('2025-07-16'), y: 20361.27 }, { x: new Date('2025-07-17'), y: 20319.36 }, { x: new Date('2025-07-19'), y: 20353.52 }, { x: new Date('2025-07-20'), y: 20345.88 }, { x: new Date('2025-07-21'), y: 20336.95 }, { x: new Date('2025-07-22'), y: 20420.75 }, { x: new Date('2025-07-23'), y: 20484.37 }, { x: new Date('2025-07-24'), y: 20509.70 }, { x: new Date('2025-07-25'), y: 20476.49 }, { x: new Date('2025-07-26'), y: 20502.34 }, { x: new Date('2025-07-27'), y: 20502.30 }, { x: new Date('2025-07-29'), y: 20383.32 }, { x: new Date('2025-07-30'), y: 20344.15 }, { x: new Date('2025-07-31'), y: 20262.97 }, { x: new Date('2025-08-01'), y: 20269.19 }, { x: new Date('2025-08-02'), y: 20349.40 }, { x: new Date('2025-08-03'), y: 20319.45 }, { x: new Date('2025-08-04'), y: 20406.54 }, { x: new Date('2025-08-05'), y: 20281.13 }, { x: new Date('2025-08-06'), y: 20274.10 }, { x: new Date('2025-08-07'), y: 20275.36 }, { x: new Date('2025-08-08'), y: 20221.99 }, { x: new Date('2025-08-09'), y: 20193.90 }, { x: new Date('2025-08-10'), y: 20178.04 }, { x: new Date('2025-08-11'), y: 20158.56 }, { x: new Date('2025-08-12'), y: 20018.42 }, { x: new Date('2025-08-13'), y: 20112.55 }, { x: new Date('2025-08-14'), y: 20117.21 }, { x: new Date('2025-08-15'), y: 19967.45 }, { x: new Date('2025-08-16'), y: 20007.05 }, { x: new Date('2025-08-18'), y: 20032.54 }, { x: new Date('2025-08-19'), y: 20028.67 }, { x: new Date('2025-08-20'), y: 20159.56 }, { x: new Date('2025-08-21'), y: 20219.24 }, { x: new Date('2025-08-22'), y: 20204.80 }, { x: new Date('2025-08-23'), y: 20301.79 }, { x: new Date('2025-08-24'), y: 20284.26 }, { x: new Date('2025-08-25'), y: 20327.63 }, { x: new Date('2025-08-26'), y: 20223.62 }, { x: new Date('2025-08-27'), y: 20264.43 }, { x: new Date('2025-08-28'), y: 20402.23 }, { x: new Date('2025-08-29'), y: 20398.89 }, { x: new Date('2025-08-30'), y: 20611.03 }, { x: new Date('2025-08-31'), y: 20592.55 }]; 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);