const fullData = [ { x: new Date('2024-02-02'), y: 440.79 }, { x: new Date('2024-02-05'), y: 442.57 }, { x: new Date('2024-02-06'), y: 440.43 }, { x: new Date('2024-02-07'), y: 441.84 }, { x: new Date('2024-02-08'), y: 439.54 }, { x: new Date('2024-02-09'), y: 437.33 }, { x: new Date('2024-02-10'), y: 434.74 }, { x: new Date('2024-02-12'), y: 434.85 }, { x: new Date('2024-02-13'), y: 434.77 }, { x: new Date('2024-02-14'), y: 434.75 }, { x: new Date('2024-05-20'), y: 442.87 }, { x: new Date('2024-08-01'), y: 456.93 }, { x: new Date('2024-08-02'), y: 458.11 }, { x: new Date('2024-08-05'), y: 458.70 }, { x: new Date('2024-08-06'), y: 457.63 }, { x: new Date('2024-08-07'), y: 450.67 }, { x: new Date('2024-08-28'), y: 455.33 }, { x: new Date('2024-08-29'), y: 453.43 }, { x: new Date('2024-08-30'), y: 484.80 }, { x: new Date('2024-09-02'), y: 455.50 }, { x: new Date('2024-09-03'), y: 454.30 }, { x: new Date('2024-09-04'), y: 452.03 }, { x: new Date('2024-09-05'), y: 454.88 }, { x: new Date('2024-09-05'), y: 458.09 }, { x: new Date('2024-09-06'), y: 458.38 }, { x: new Date('2024-09-07'), y: 458.16 }, { x: new Date('2024-09-08'), y: 458.16 }, { x: new Date('2024-09-09'), y: 457.26 }, { x: new Date('2024-09-10'), y: 455.64 }, { x: new Date('2024-09-19'), y: 459.61 }, { x: new Date('2024-09-20'), y: 455.93 }, { x: new Date('2024-09-23'), y: 460.51 }, { x: new Date('2024-09-24'), y: 460.60 }, { x: new Date('2024-09-25'), y: 461.42 }, { x: new Date('2024-09-26'), y: 464.84 }, { x: new Date('2024-09-27'), y: 467.25 }, { x: new Date('2024-10-01'), y: 468.86 }, { x: new Date('2024-10-02'), y: 467.80 }, { x: new Date('2024-10-03'), y: 466.29 }, { x: new Date('2024-10-04'), y: 467.78 }, { x: new Date('2024-10-05'), y: 470.88 }, { x: new Date('2024-10-07'), y: 469.97 }, { x: new Date('2024-10-08'), y: 467.64 }, { x: new Date('2024-10-10'), y: 468.87 }, { x: new Date('2024-10-11'), y: 468.63 }, { x: new Date('2024-10-12'), y: 469.59 }, { x: new Date('2024-10-14'), y: 467.96 }, { x: new Date('2024-10-15'), y: 466.33 }, { x: new Date('2024-10-16'), y: 466.89 }, { x: new Date('2024-10-17'), y: 468.64 }, { x: new Date('2024-10-18'), y: 467.53 }, { x: new Date('2024-10-19'), y: 466.87 }, { x: new Date('2024-10-20'), y: 466.87 }, { x: new Date('2024-10-21'), y: 466.87 }, { x: new Date('2024-10-22'), y: 464.32 }, { x: new Date('2024-10-23'), y: 464.98 }, { x: new Date('2024-10-24'), y: 462.47 }, { x: new Date('2024-10-25'), y: 464.30 }, { x: new Date('2024-10-26'), y: 466.76 }, { x: new Date('2024-10-27'), y: 466.76 }, { x: new Date('2024-10-28'), y: 463.27 }, { x: new Date('2024-10-29'), y: 466.27 }, { x: new Date('2024-10-30'), y: 467.95 }, { x: new Date('2024-10-31'), y: 464.33 }, { x: new Date('2024-11-01'), y: 464.93 }, { x: new Date('2024-11-02'), y: 467.11 }, { x: new Date('2024-11-03'), y: 467.11 }, { x: new Date('2024-11-04'), y: 467.11 }, { x: new Date('2024-11-05'), y: 467.34 }, { x: new Date('2024-11-06'), y: 467.96 }, { x: new Date('2024-11-07'), y: 460.56 }, { x: new Date('2024-11-08'), y: 458.36 }, { x: new Date('2024-11-09'), y: 457.47 }, { x: new Date('2024-11-10'), y: 457.47 }, { x: new Date('2024-11-11'), y: 456.98 }, { x: new Date('2024-11-12'), y: 456.89 }, { x: new Date('2024-11-13'), y: 453.83 }, { x: new Date('2024-11-14'), y: 452.59 }, { x: new Date('2024-11-15'), y: 456.45 }, { x: new Date('2024-11-16'), y: 456.77 }, { x: new Date('2024-11-17'), y: 456.77 }, { x: new Date('2024-11-18'), y: 456.39 }, { x: new Date('2024-11-19'), y: 458.18 }, { x: new Date('2024-11-21'), y: 460.06 }, { x: new Date('2024-11-22'), y: 458.23 }, { x: new Date('2024-11-23'), y: 462.39 }, { x: new Date('2024-11-24'), y: 462.39 }, { x: new Date('2024-11-26'), y: 457.25 }, { x: new Date('2024-11-27'), y: 458.77 }, { x: new Date('2024-11-28'), y: 459.83 }, { x: new Date('2024-11-29'), y: 462.49 }, { x: new Date('2024-12-01'), y: 461.66 }, { x: new Date('2024-12-02'), y: 460.15 }, { x: new Date('2024-12-03'), y: 463.38 }, { x: new Date('2024-12-04'), y: 464.96 }, { x: new Date('2024-12-06'), y: 465.49 }, { x: new Date('2024-12-07'), y: 465.53 }, { x: new Date('2024-12-08'), y: 465.53 }, { x: new Date('2024-12-09'), y: 465.53 }, { x: new Date('2024-12-10'), y: 469.20 }, { x: new Date('2024-12-11'), y: 471.84 }, { x: new Date('2024-12-12'), y: 471.90 }, { x: new Date('2024-12-13'), y: 469.37 }, { x: new Date('2024-12-14'), y: 469.79 }, { x: new Date('2024-12-15'), y: 469.79 }, { x: new Date('2024-12-16'), y: 469.60 }, { x: new Date('2024-12-17'), y: 470.57 }, { x: new Date('2024-12-18'), y: 470.66 }, { x: new Date('2024-12-19'), y: 470.58 }, { x: new Date('2024-12-20'), y: 471.25 }, { x: new Date('2024-12-22'), y: 472.96 }, { x: new Date('2024-12-23'), y: 472.96 }, { x: new Date('2024-12-24'), y: 473.27 }, { x: new Date('2024-12-25'), y: 474.95 }, { x: new Date('2024-12-27'), y: 475.43 }, { x: new Date('2024-12-30'), y: 476.52 }, { x: new Date('2024-12-31'), y: 472.67 }, { x: new Date('2025-01-02'), y: 475.47 }, { x: new Date('2025-01-03'), y: 471.60 }, { x: new Date('2025-01-04'), y: 469.39 }, { x: new Date('2025-01-06'), y: 469.39 }, { x: new Date('2025-01-15'), y: 468.70 }, { x: new Date('2025-01-16'), y: 474.66 }, { x: new Date('2025-01-17'), y: 474.75 }, { x: new Date('2025-01-19'), y: 476.36 }, { x: new Date('2025-01-20'), y: 475.17 }, { x: new Date('2025-01-21'), y: 478.13 }, { x: new Date('2025-01-22'), y: 481.73 }, { x: new Date('2025-01-23'), y: 480.41 }, { x: new Date('2025-01-24'), y: 477.35 }, { x: new Date('2025-01-25'), y: 481.63 }, { x: new Date('2025-01-26'), y: 481.63 }, { x: new Date('2025-01-27'), y: 480.53 }, { x: new Date('2025-01-28'), y: 478.36 }, { x: new Date('2025-01-29'), y: 479.32 }, { x: new Date('2025-01-31'), y: 484.20 }, { x: new Date('2025-02-01'), y: 483.72 }, { x: new Date('2025-02-03'), y: 480.32 }, { x: new Date('2025-02-04'), y: 482.04 }, { x: new Date('2025-02-06'), y: 485.10 }, { x: new Date('2025-02-07'), y: 483.21 }, { x: new Date('2025-02-08'), y: 483.88 }, { x: new Date('2025-02-09'), y: 483.85 }, { x: new Date('2025-02-10'), y: 480.77 }, { x: new Date('2025-02-11'), y: 480.77 }, { x: new Date('2025-02-12'), y: 482.17 }, { x: new Date('2025-02-13'), y: 479.96 }, { x: new Date('2025-02-14'), y: 484.28 }, { x: new Date('2025-02-17'), y: 483.10 }, { x: new Date('2025-02-18'), y: 481.04 }, { x: new Date('2025-02-19'), y: 483.60 }, { x: new Date('2025-02-20'), y: 484.55 }, { x: new Date('2025-02-24'), y: 485.27 }, { x: new Date('2025-02-25'), y: 485.79 }, { x: new Date('2025-02-26'), y: 484.46 }, { x: new Date('2025-02-27'), y: 485.12 }, { x: new Date('2025-02-28'), y: 484.27 }, { x: new Date('2025-03-01'), y: 484.33 }, { x: new Date('2025-03-02'), y: 484.46 }, { x: new Date('2025-03-03'), y: 481.15 }, { x: new Date('2025-03-04'), y: 482.30 }, { x: new Date('2025-03-06'), y: 485.29 }, { x: new Date('2025-03-07'), y: 484.46 }, { x: new Date('2025-03-08'), y: 484.24 }, { x: new Date('2025-03-10'), y: 483.00 }, { x: new Date('2025-03-11'), y: 482.53 }, { x: new Date('2025-03-12'), y: 485.63 }, { x: new Date('2025-03-13'), y: 485.79 }, { x: new Date('2025-03-14'), y: 485.88 }, { x: new Date('2025-03-15'), y: 485.71 }, { x: new Date('2025-03-16'), y: 485.56 }, { x: new Date('2025-03-17'), y: 485.56 }, { x: new Date('2025-03-18'), y: 486.01 }, { x: new Date('2025-03-19'), y: 489.39 }, { x: new Date('2025-03-20'), y: 491.01 }, { x: new Date('2025-03-21'), y: 488.22 }, { x: new Date('2025-03-22'), y: 486.98 }, { x: new Date('2025-03-23'), y: 486.95 }, { x: new Date('2025-03-24'), y: 487.66 }, { x: new Date('2025-03-25'), y: 487.66 }, { x: new Date('2025-03-26'), y: 489.02 }, { x: new Date('2025-03-27'), y: 487.38 }, { x: new Date('2025-03-28'), y: 488.32 }, { x: new Date('2025-03-30'), y: 487.48 }, { x: new Date('2025-03-31'), y: 487.84 }, { x: new Date('2025-04-01'), y: 488.55 }, { x: new Date('2025-04-02'), y: 486.24 }, { x: new Date('2025-04-03'), y: 483.30 }, { x: new Date('2025-04-04'), y: 484.03 }, { x: new Date('2025-04-05'), y: 484.93 }, { x: new Date('2025-04-06'), y: 486.21 }, { x: new Date('2025-04-07'), y: 482.54 }, { x: new Date('2025-04-08'), y: 479.81 }, { x: new Date('2025-04-09'), y: 485.65 }, { x: new Date('2025-04-10'), y: 491.38 }, { x: new Date('2025-04-11'), y: 494.86 }, { x: new Date('2025-04-12'), y: 501.07 }, { x: new Date('2025-04-13'), y: 501.02 }, { x: new Date('2025-04-14'), y: 502.22 }, { x: new Date('2025-04-15'), y: 501.05 }, { x: new Date('2025-04-16'), y: 501.99 }, { x: new Date('2025-04-17'), y: 507.51 }, { x: new Date('2025-04-18'), y: 508.42 }, { x: new Date('2025-04-19'), y: 504.44 }, { x: new Date('2025-04-20'), y: 504.59 }, { x: new Date('2025-04-21'), y: 505.56 }, { x: new Date('2025-04-22'), y: 508.00 }, { x: new Date('2025-04-23'), y: 504.84 }, { x: new Date('2025-04-24'), y: 503.99 }, { x: new Date('2025-04-26'), y: 502.30 }, { x: new Date('2025-04-27'), y: 502.44 }, { x: new Date('2025-04-28'), y: 502.89 }, { x: new Date('2025-05-02'), y: 496.93 }, { x: new Date('2025-05-05'), y: 494.40 }, { x: new Date('2025-05-06'), y: 494.40 }, { x: new Date('2025-05-08'), y: 502.43 }, { x: new Date('2025-05-09'), y: 500.34 }, { x: new Date('2025-05-10'), y: 500.84 }, { x: new Date('2025-05-11'), y: 500.63 }, { x: new Date('2025-05-12'), y: 498.96 }, { x: new Date('2025-05-13'), y: 494.68 }, { x: new Date('2025-05-14'), y: 497.41 }, { x: new Date('2025-05-15'), y: 495.27 }, { x: new Date('2025-05-16'), y: 495.61 }, { x: new Date('2025-05-17'), y: 492.20 }, { x: new Date('2025-05-19'), y: 493.62 }, { x: new Date('2025-05-20'), y: 495.91 }, { x: new Date('2025-05-21'), y: 496.75 }, { x: new Date('2025-05-22'), y: 499.37 }, { x: new Date('2025-05-24'), y: 498.82 }, { x: new Date('2025-05-26'), y: 497.93 }, { x: new Date('2025-05-27'), y: 498.17 }, { x: new Date('2025-06-04'), y: 499.39 }, { x: new Date('2025-06-05'), y: 498.54 }, { x: new Date('2025-06-06'), y: 499.67 }, { x: new Date('2025-06-07'), y: 499.48 }, { x: new Date('2025-06-08'), y: 499.46 }, { x: new Date('2025-06-10'), y: 498.04 }, { x: new Date('2025-06-11'), y: 497.59 }, { x: new Date('2025-06-12'), y: 498.41 }, { x: new Date('2025-06-13'), y: 500.28 }, { x: new Date('2025-06-14'), y: 502.60 }, { x: new Date('2025-06-15'), y: 502.45 }, { x: new Date('2025-06-16'), y: 501.73 }, { x: new Date('2025-06-17'), y: 500.73 }, { x: new Date('2025-06-18'), y: 499.66 }, { x: new Date('2025-06-20'), y: 499.54 }, { x: new Date('2025-06-21'), y: 499.32 }, { x: new Date('2025-06-22'), y: 499.22 }, { x: new Date('2025-06-23'), y: 497.94 }, { x: new Date('2025-06-24'), y: 499.88 }, { x: new Date('2025-06-25'), y: 499.84 }, { x: new Date('2025-06-26'), y: 499.66 }, { x: new Date('2025-06-27'), y: 498.89 }, { x: new Date('2025-06-28'), y: 496.91 }, { x: new Date('2025-06-29'), y: 496.91 }, { x: new Date('2025-06-30'), y: 496.83 }, { x: new Date('2025-07-01'), y: 499.28 }, { x: new Date('2025-07-02'), y: 499.17 }, { x: new Date('2025-07-04'), y: 499.66 }, { x: new Date('2025-07-05'), y: 500.00 }, { x: new Date('2025-07-06'), y: 500.02 }, { x: new Date('2025-07-07'), y: 499.44 }, { x: new Date('2025-07-08'), y: 497.34 }, { x: new Date('2025-07-09'), y: 498.17 }, { x: new Date('2025-07-10'), y: 496.53 }, { x: new Date('2025-07-12'), y: 499.17 }, { x: new Date('2025-07-13'), y: 498.88 }, { x: new Date('2025-07-14'), y: 497.36 }, { x: new Date('2025-07-16'), y: 499.62 }, { x: new Date('2025-07-17'), y: 500.57 }, { x: new Date('2025-07-19'), y: 502.72 }, { x: new Date('2025-07-20'), y: 502.69 }, { x: new Date('2025-07-21'), y: 502.27 }, { x: new Date('2025-07-22'), y: 504.61 }, { x: new Date('2025-07-23'), y: 505.66 }, { x: new Date('2025-07-24'), y: 506.04 }, { x: new Date('2025-07-25'), y: 504.59 }, { x: new Date('2025-07-26'), y: 503.68 }, { x: new Date('2025-07-27'), y: 503.72 }, { x: new Date('2025-07-29'), y: 503.28 }, { x: new Date('2025-07-30'), y: 505.04 }, { x: new Date('2025-07-31'), y: 502.45 }, { x: new Date('2025-08-01'), y: 502.77 }, { x: new Date('2025-08-02'), y: 504.13 }, { x: new Date('2025-08-03'), y: 503.42 }, { x: new Date('2025-08-04'), y: 503.04 }, { x: new Date('2025-08-05'), y: 505.14 }, { x: new Date('2025-08-06'), y: 505.30 }, { x: new Date('2025-08-07'), y: 504.78 }, { x: new Date('2025-08-08'), y: 504.02 }, { x: new Date('2025-08-09'), y: 503.31 }, { x: new Date('2025-08-10'), y: 503.13 }, { x: new Date('2025-08-11'), y: 502.25 }, { x: new Date('2025-08-12'), y: 501.61 }, { x: new Date('2025-08-13'), y: 501.77 }, { x: new Date('2025-08-14'), y: 500.45 }, { x: new Date('2025-08-15'), y: 496.81 }, { x: new Date('2025-08-16'), y: 497.09 }, { x: new Date('2025-08-18'), y: 497.67 }, { x: new Date('2025-08-19'), y: 497.79 }, { x: new Date('2025-08-20'), y: 498.86 }, { x: new Date('2025-08-21'), y: 499.34 }, { x: new Date('2025-08-22'), y: 498.83 }, { x: new Date('2025-08-23'), y: 502.58 }, { x: new Date('2025-08-24'), y: 501.91 }, { x: new Date('2025-08-25'), y: 502.46 }, { x: new Date('2025-08-26'), y: 500.31 }, { x: new Date('2025-08-27'), y: 501.88 }, { x: new Date('2025-08-28'), y: 504.08 }, { x: new Date('2025-08-29'), y: 504.78 }, { x: new Date('2025-08-30'), y: 509.00 }]; 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);