const fullData = [ { x: new Date('2025-04-09'), y: 4616.92 }, { x: new Date('2025-04-10'), y: 4595.57 }, { x: new Date('2025-04-11'), y: 4587.18 }, { x: new Date('2025-04-12'), y: 4573.39 }, { x: new Date('2025-04-13'), y: 4574.86 }, { x: new Date('2025-04-14'), y: 4579.26 }, { x: new Date('2025-04-15'), y: 4569.23 }, { x: new Date('2025-04-16'), y: 4581.80 }, { x: new Date('2025-04-17'), y: 4575.70 }, { x: new Date('2025-04-18'), y: 4592.77 }, { x: new Date('2025-04-19'), y: 4590.45 }, { x: new Date('2025-04-20'), y: 4590.71 }, { x: new Date('2025-04-21'), y: 4588.92 }, { x: new Date('2025-04-22'), y: 4584.34 }, { x: new Date('2025-04-23'), y: 4592.49 }, { x: new Date('2025-04-24'), y: 4596.80 }, { x: new Date('2025-04-26'), y: 4588.35 }, { x: new Date('2025-04-27'), y: 4588.31 }, { x: new Date('2025-04-28'), y: 4584.65 }, { x: new Date('2025-05-02'), y: 4528.69 }, { x: new Date('2025-05-05'), y: 4486.58 }, { x: new Date('2025-05-06'), y: 4486.58 }, { x: new Date('2025-05-08'), y: 4476.56 }, { x: new Date('2025-05-09'), y: 4502.87 }, { x: new Date('2025-05-10'), y: 4508.00 }, { x: new Date('2025-05-11'), y: 4506.04 }, { x: new Date('2025-05-12'), y: 4507.02 }, { x: new Date('2025-05-13'), y: 4518.62 }, { x: new Date('2025-05-14'), y: 4507.90 }, { x: new Date('2025-05-15'), y: 4513.91 }, { x: new Date('2025-05-16'), y: 4494.40 }, { x: new Date('2025-05-17'), y: 4484.02 }, { x: new Date('2025-05-19'), y: 4486.91 }, { x: new Date('2025-05-20'), y: 4479.10 }, { x: new Date('2025-05-21'), y: 4471.22 }, { x: new Date('2025-05-22'), y: 4464.58 }, { x: new Date('2025-05-24'), y: 4419.29 }, { x: new Date('2025-05-26'), y: 4422.64 }, { x: new Date('2025-05-27'), y: 4419.99 }, { x: new Date('2025-06-04'), y: 4444.92 }, { x: new Date('2025-06-05'), y: 4438.80 }, { x: new Date('2025-06-06'), y: 4429.66 }, { x: new Date('2025-06-07'), y: 4439.33 }, { x: new Date('2025-06-08'), y: 4438.39 }, { x: new Date('2025-06-10'), y: 4434.67 }, { x: new Date('2025-06-11'), y: 4430.99 }, { x: new Date('2025-06-12'), y: 4429.99 }, { x: new Date('2025-06-13'), y: 4418.96 }, { x: new Date('2025-06-14'), y: 4444.58 }, { x: new Date('2025-06-15'), y: 4443.27 }, { x: new Date('2025-06-16'), y: 4439.35 }, { x: new Date('2025-06-17'), y: 4437.71 }, { x: new Date('2025-06-18'), y: 4436.44 }, { x: new Date('2025-06-20'), y: 4461.48 }, { x: new Date('2025-06-21'), y: 4463.75 }, { x: new Date('2025-06-22'), y: 4466.12 }, { x: new Date('2025-06-23'), y: 4467.61 }, { x: new Date('2025-06-24'), y: 4492.72 }, { x: new Date('2025-06-25'), y: 4445.21 }, { x: new Date('2025-06-26'), y: 4441.91 }, { x: new Date('2025-06-27'), y: 4415.65 }, { x: new Date('2025-06-28'), y: 4421.84 }, { x: new Date('2025-06-29'), y: 4420.99 }, { x: new Date('2025-06-30'), y: 4419.37 }, { x: new Date('2025-07-01'), y: 4415.09 }, { x: new Date('2025-07-02'), y: 4415.17 }, { x: new Date('2025-07-04'), y: 4411.98 }, { x: new Date('2025-07-05'), y: 4410.75 }, { x: new Date('2025-07-06'), y: 4410.28 }, { x: new Date('2025-07-07'), y: 4410.65 }, { x: new Date('2025-07-08'), y: 4426.33 }, { x: new Date('2025-07-09'), y: 4428.23 }, { x: new Date('2025-07-10'), y: 4428.52 }, { x: new Date('2025-07-12'), y: 4420.75 }, { x: new Date('2025-07-13'), y: 4420.65 }, { x: new Date('2025-07-14'), y: 4421.66 }, { x: new Date('2025-07-16'), y: 4433.14 }, { x: new Date('2025-07-17'), y: 4439.32 }, { x: new Date('2025-07-19'), y: 4439.65 }, { x: new Date('2025-07-20'), y: 4443.13 }, { x: new Date('2025-07-21'), y: 4438.38 }, { x: new Date('2025-07-22'), y: 4442.35 }, { x: new Date('2025-07-23'), y: 4435.04 }, { x: new Date('2025-07-24'), y: 4430.45 }, { x: new Date('2025-07-25'), y: 4433.87 }, { x: new Date('2025-07-26'), y: 4448.48 }, { x: new Date('2025-07-27'), y: 4447.49 }, { x: new Date('2025-07-29'), y: 4458.23 }, { x: new Date('2025-07-30'), y: 4463.55 }, { x: new Date('2025-07-31'), y: 4473.75 }, { x: new Date('2025-08-01'), y: 4488.45 }, { x: new Date('2025-08-02'), y: 4476.93 }, { x: new Date('2025-08-03'), y: 4480.67 }, { x: new Date('2025-08-04'), y: 4476.27 }, { x: new Date('2025-08-05'), y: 4461.95 }, { x: new Date('2025-08-06'), y: 4462.78 }, { x: new Date('2025-08-07'), y: 4454.96 }, { x: new Date('2025-08-08'), y: 4443.77 }, { x: new Date('2025-08-09'), y: 4438.92 }, { x: new Date('2025-08-10'), y: 4437.63 }, { x: new Date('2025-08-11'), y: 4433.34 }, { x: new Date('2025-08-12'), y: 4433.41 }, { x: new Date('2025-08-13'), y: 4429.58 }, { x: new Date('2025-08-14'), y: 4395.44 }, { x: new Date('2025-08-15'), y: 4393.75 }, { x: new Date('2025-08-16'), y: 4400.76 }, { x: new Date('2025-08-18'), y: 4407.32 }, { x: new Date('2025-08-19'), y: 4414.25 }, { x: new Date('2025-08-20'), y: 4430.32 }, { x: new Date('2025-08-21'), y: 4435.10 }, { x: new Date('2025-08-22'), y: 4445.23 }, { x: new Date('2025-08-23'), y: 4438.23 }, { x: new Date('2025-08-24'), y: 4437.28 }, { x: new Date('2025-08-25'), y: 4437.26 }, { x: new Date('2025-08-26'), y: 4428.68 }, { x: new Date('2025-08-27'), y: 4438.47 }, { x: new Date('2025-08-28'), y: 4464.14 }, { x: new Date('2025-08-29'), y: 4452.23 }, { x: new Date('2025-08-30'), y: 4488.68 }, { x: new Date('2025-08-31'), y: 4485.87 }]; 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);