const fullData = [ { x: new Date('2024-02-02'), y: 501.65 }, { x: new Date('2024-02-05'), y: 501.16 }, { x: new Date('2024-02-06'), y: 502.11 }, { x: new Date('2024-02-07'), y: 499.94 }, { x: new Date('2024-02-08'), y: 498.82 }, { x: new Date('2024-02-09'), y: 500.19 }, { x: new Date('2024-02-10'), y: 497.45 }, { x: new Date('2024-02-12'), y: 497.43 }, { x: new Date('2024-02-13'), y: 496.91 }, { x: new Date('2024-02-14'), y: 498.00 }, { x: new Date('2024-05-20'), y: 495.58 }, { x: new Date('2024-08-01'), y: 496.08 }, { x: new Date('2024-08-02'), y: 495.18 }, { x: new Date('2024-08-05'), y: 493.90 }, { x: new Date('2024-08-06'), y: 495.05 }, { x: new Date('2024-08-07'), y: 491.17 }, { x: new Date('2024-08-28'), y: 484.53 }, { x: new Date('2024-08-29'), y: 482.33 }, { x: new Date('2024-08-30'), y: 484.80 }, { x: new Date('2024-09-02'), y: 485.28 }, { x: new Date('2024-09-03'), y: 485.19 }, { x: new Date('2024-09-04'), y: 481.81 }, { x: new Date('2024-09-05'), y: 480.48 }, { x: new Date('2024-09-05'), y: 480.55 }, { x: new Date('2024-09-06'), y: 481.22 }, { x: new Date('2024-09-07'), y: 482.47 }, { x: new Date('2024-09-08'), y: 482.47 }, { x: new Date('2024-09-09'), y: 480.77 }, { x: new Date('2024-09-10'), y: 479.80 }, { x: new Date('2024-09-19'), y: 479.81 }, { x: new Date('2024-09-20'), y: 472.99 }, { x: new Date('2024-09-23'), y: 473.78 }, { x: new Date('2024-09-24'), y: 473.98 }, { x: new Date('2024-09-25'), y: 473.20 }, { x: new Date('2024-09-26'), y: 474.99 }, { x: new Date('2024-09-27'), y: 477.91 }, { x: new Date('2024-10-01'), y: 477.34 }, { x: new Date('2024-10-02'), y: 478.33 }, { x: new Date('2024-10-03'), y: 480.46 }, { x: new Date('2024-10-04'), y: 483.12 }, { x: new Date('2024-10-05'), y: 485.35 }, { x: new Date('2024-10-07'), y: 485.22 }, { x: new Date('2024-10-08'), y: 488.07 }, { x: new Date('2024-10-10'), y: 487.74 }, { x: new Date('2024-10-11'), y: 485.71 }, { x: new Date('2024-10-12'), y: 483.83 }, { x: new Date('2024-10-14'), y: 484.34 }, { x: new Date('2024-10-15'), y: 483.93 }, { x: new Date('2024-10-16'), y: 483.59 }, { x: new Date('2024-10-17'), y: 483.09 }, { x: new Date('2024-10-18'), y: 483.90 }, { x: new Date('2024-10-19'), y: 482.64 }, { x: new Date('2024-10-20'), y: 482.64 }, { x: new Date('2024-10-21'), y: 482.64 }, { x: new Date('2024-10-22'), y: 485.23 }, { x: new Date('2024-10-23'), y: 486.24 }, { x: new Date('2024-10-24'), y: 487.67 }, { x: new Date('2024-10-25'), y: 488.67 }, { x: new Date('2024-10-26'), y: 489.79 }, { x: new Date('2024-10-27'), y: 489.79 }, { x: new Date('2024-10-28'), y: 487.55 }, { x: new Date('2024-10-29'), y: 491.87 }, { x: new Date('2024-10-30'), y: 490.84 }, { x: new Date('2024-10-31'), y: 490.77 }, { x: new Date('2024-11-01'), y: 493.81 }, { x: new Date('2024-11-02'), y: 496.25 }, { x: new Date('2024-11-03'), y: 496.25 }, { x: new Date('2024-11-04'), y: 496.25 }, { x: new Date('2024-11-05'), y: 493.04 }, { x: new Date('2024-11-06'), y: 493.68 }, { x: new Date('2024-11-07'), y: 489.87 }, { x: new Date('2024-11-08'), y: 485.72 }, { x: new Date('2024-11-09'), y: 485.27 }, { x: new Date('2024-11-10'), y: 485.27 }, { x: new Date('2024-11-11'), y: 486.27 }, { x: new Date('2024-11-12'), y: 486.94 }, { x: new Date('2024-11-13'), y: 488.02 }, { x: new Date('2024-11-14'), y: 486.41 }, { x: new Date('2024-11-15'), y: 490.42 }, { x: new Date('2024-11-16'), y: 489.38 }, { x: new Date('2024-11-17'), y: 489.38 }, { x: new Date('2024-11-18'), y: 488.18 }, { x: new Date('2024-11-19'), y: 488.27 }, { x: new Date('2024-11-21'), y: 488.67 }, { x: new Date('2024-11-22'), y: 489.79 }, { x: new Date('2024-11-23'), y: 489.02 }, { x: new Date('2024-11-24'), y: 489.02 }, { x: new Date('2024-11-26'), y: 489.65 }, { x: new Date('2024-11-27'), y: 489.49 }, { x: new Date('2024-11-28'), y: 487.53 }, { x: new Date('2024-11-29'), y: 487.42 }, { x: new Date('2024-12-01'), y: 487.85 }, { x: new Date('2024-12-02'), y: 488.88 }, { x: new Date('2024-12-03'), y: 488.16 }, { x: new Date('2024-12-04'), y: 491.85 }, { x: new Date('2024-12-06'), y: 489.27 }, { x: new Date('2024-12-07'), y: 489.52 }, { x: new Date('2024-12-08'), y: 489.52 }, { x: new Date('2024-12-09'), y: 489.52 }, { x: new Date('2024-12-10'), y: 488.88 }, { x: new Date('2024-12-11'), y: 489.72 }, { x: new Date('2024-12-12'), y: 490.13 }, { x: new Date('2024-12-13'), y: 490.88 }, { x: new Date('2024-12-14'), y: 492.94 }, { x: new Date('2024-12-15'), y: 492.94 }, { x: new Date('2024-12-16'), y: 493.40 }, { x: new Date('2024-12-17'), y: 494.76 }, { x: new Date('2024-12-18'), y: 494.64 }, { x: new Date('2024-12-19'), y: 498.49 }, { x: new Date('2024-12-20'), y: 499.97 }, { x: new Date('2024-12-22'), y: 495.85 }, { x: new Date('2024-12-23'), y: 495.85 }, { x: new Date('2024-12-24'), y: 497.41 }, { x: new Date('2024-12-25'), y: 496.02 }, { x: new Date('2024-12-27'), y: 495.23 }, { x: new Date('2024-12-30'), y: 494.86 }, { x: new Date('2024-12-31'), y: 492.31 }, { x: new Date('2025-01-02'), y: 494.79 }, { x: new Date('2025-01-03'), y: 493.65 }, { x: new Date('2025-01-04'), y: 491.79 }, { x: new Date('2025-01-06'), y: 491.79 }, { x: new Date('2025-01-15'), y: 493.78 }, { x: new Date('2025-01-16'), y: 497.21 }, { x: new Date('2025-01-17'), y: 498.77 }, { x: new Date('2025-01-19'), y: 497.75 }, { x: new Date('2025-01-20'), y: 497.29 }, { x: new Date('2025-01-21'), y: 501.25 }, { x: new Date('2025-01-22'), y: 499.37 }, { x: new Date('2025-01-23'), y: 497.87 }, { x: new Date('2025-01-24'), y: 497.15 }, { x: new Date('2025-01-25'), y: 493.86 }, { x: new Date('2025-01-26'), y: 493.86 }, { x: new Date('2025-01-27'), y: 493.83 }, { x: new Date('2025-01-28'), y: 491.14 }, { x: new Date('2025-01-29'), y: 493.32 }, { x: new Date('2025-01-31'), y: 494.34 }, { x: new Date('2025-02-01'), y: 496.42 }, { x: new Date('2025-02-03'), y: 496.16 }, { x: new Date('2025-02-04'), y: 494.72 }, { x: new Date('2025-02-06'), y: 495.90 }, { x: new Date('2025-02-07'), y: 497.20 }, { x: new Date('2025-02-08'), y: 496.58 }, { x: new Date('2025-02-09'), y: 496.54 }, { x: new Date('2025-02-10'), y: 496.64 }, { x: new Date('2025-02-11'), y: 496.64 }, { x: new Date('2025-02-12'), y: 497.44 }, { x: new Date('2025-02-13'), y: 498.91 }, { x: new Date('2025-02-14'), y: 499.32 }, { x: new Date('2025-02-17'), y: 496.88 }, { x: new Date('2025-02-18'), y: 495.85 }, { x: new Date('2025-02-19'), y: 498.33 }, { x: new Date('2025-02-20'), y: 499.24 }, { x: new Date('2025-02-24'), y: 497.98 }, { x: new Date('2025-02-25'), y: 498.51 }, { x: new Date('2025-02-26'), y: 499.52 }, { x: new Date('2025-02-27'), y: 499.16 }, { x: new Date('2025-02-28'), y: 501.11 }, { x: new Date('2025-03-01'), y: 503.49 }, { x: new Date('2025-03-02'), y: 503.51 }, { x: new Date('2025-03-03'), y: 502.78 }, { x: new Date('2025-03-04'), y: 500.03 }, { x: new Date('2025-03-06'), y: 497.38 }, { x: new Date('2025-03-07'), y: 496.40 }, { x: new Date('2025-03-08'), y: 497.44 }, { x: new Date('2025-03-10'), y: 496.92 }, { x: new Date('2025-03-11'), y: 498.39 }, { x: new Date('2025-03-12'), y: 500.20 }, { x: new Date('2025-03-13'), y: 499.25 }, { x: new Date('2025-03-14'), y: 497.44 }, { x: new Date('2025-03-15'), y: 496.44 }, { x: new Date('2025-03-16'), y: 496.26 }, { x: new Date('2025-03-17'), y: 496.26 }, { x: new Date('2025-03-18'), y: 496.74 }, { x: new Date('2025-03-19'), y: 499.64 }, { x: new Date('2025-03-20'), y: 500.40 }, { x: new Date('2025-03-21'), y: 499.91 }, { x: new Date('2025-03-22'), y: 500.68 }, { x: new Date('2025-03-23'), y: 501.13 }, { x: new Date('2025-03-24'), y: 500.82 }, { x: new Date('2025-03-25'), y: 500.82 }, { x: new Date('2025-03-26'), y: 502.43 }, { x: new Date('2025-03-27'), y: 501.34 }, { x: new Date('2025-03-28'), y: 501.52 }, { x: new Date('2025-03-30'), y: 500.82 }, { x: new Date('2025-03-31'), y: 500.37 }, { x: new Date('2025-04-01'), y: 499.51 }, { x: new Date('2025-04-02'), y: 500.32 }, { x: new Date('2025-04-03'), y: 502.58 }, { x: new Date('2025-04-04'), y: 503.54 }, { x: new Date('2025-04-05'), y: 505.87 }, { x: new Date('2025-04-06'), y: 508.11 }, { x: new Date('2025-04-07'), y: 506.32 }, { x: new Date('2025-04-08'), y: 506.62 }, { x: new Date('2025-04-09'), y: 513.59 }, { x: new Date('2025-04-10'), y: 516.89 }, { x: new Date('2025-04-11'), y: 514.82 }, { x: new Date('2025-04-12'), y: 521.86 }, { x: new Date('2025-04-13'), y: 521.61 }, { x: new Date('2025-04-14'), y: 522.84 }, { x: new Date('2025-04-15'), y: 519.93 }, { x: new Date('2025-04-16'), y: 519.00 }, { x: new Date('2025-04-17'), y: 520.53 }, { x: new Date('2025-04-18'), y: 520.46 }, { x: new Date('2025-04-19'), y: 519.71 }, { x: new Date('2025-04-20'), y: 519.66 }, { x: new Date('2025-04-21'), y: 518.99 }, { x: new Date('2025-04-22'), y: 520.08 }, { x: new Date('2025-04-23'), y: 519.55 }, { x: new Date('2025-04-24'), y: 520.04 }, { x: new Date('2025-04-26'), y: 518.90 }, { x: new Date('2025-04-27'), y: 518.94 }, { x: new Date('2025-04-28'), y: 518.83 }, { x: new Date('2025-05-02'), y: 518.90 }, { x: new Date('2025-05-05'), y: 539.91 }, { x: new Date('2025-05-06'), y: 539.91 }, { x: new Date('2025-05-08'), y: 552.59 }, { x: new Date('2025-05-09'), y: 547.74 }, { x: new Date('2025-05-10'), y: 551.29 }, { x: new Date('2025-05-11'), y: 551.06 }, { x: new Date('2025-05-12'), y: 551.35 }, { x: new Date('2025-05-13'), y: 548.02 }, { x: new Date('2025-05-14'), y: 545.02 }, { x: new Date('2025-05-15'), y: 548.04 }, { x: new Date('2025-05-16'), y: 548.31 }, { x: new Date('2025-05-17'), y: 546.63 }, { x: new Date('2025-05-19'), y: 547.05 }, { x: new Date('2025-05-20'), y: 547.21 }, { x: new Date('2025-05-21'), y: 545.68 }, { x: new Date('2025-05-22'), y: 547.84 }, { x: new Date('2025-05-24'), y: 543.81 }, { x: new Date('2025-05-26'), y: 544.95 }, { x: new Date('2025-05-27'), y: 545.50 }, { x: new Date('2025-06-04'), y: 545.81 }, { x: new Date('2025-06-05'), y: 545.38 }, { x: new Date('2025-06-06'), y: 544.61 }, { x: new Date('2025-06-07'), y: 546.12 }, { x: new Date('2025-06-08'), y: 545.90 }, { x: new Date('2025-06-10'), y: 545.37 }, { x: new Date('2025-06-11'), y: 545.11 }, { x: new Date('2025-06-12'), y: 545.72 }, { x: new Date('2025-06-13'), y: 552.37 }, { x: new Date('2025-06-14'), y: 554.65 }, { x: new Date('2025-06-15'), y: 554.15 }, { x: new Date('2025-06-16'), y: 554.31 }, { x: new Date('2025-06-17'), y: 556.04 }, { x: new Date('2025-06-18'), y: 552.13 }, { x: new Date('2025-06-20'), y: 554.17 }, { x: new Date('2025-06-21'), y: 556.46 }, { x: new Date('2025-06-22'), y: 557.56 }, { x: new Date('2025-06-23'), y: 557.29 }, { x: new Date('2025-06-24'), y: 556.42 }, { x: new Date('2025-06-25'), y: 555.36 }, { x: new Date('2025-06-26'), y: 557.89 }, { x: new Date('2025-06-27'), y: 558.98 }, { x: new Date('2025-06-28'), y: 560.98 }, { x: new Date('2025-06-29'), y: 562.59 }, { x: new Date('2025-06-30'), y: 561.80 }, { x: new Date('2025-07-01'), y: 557.06 }, { x: new Date('2025-07-02'), y: 557.25 }, { x: new Date('2025-07-04'), y: 561.89 }, { x: new Date('2025-07-05'), y: 561.27 }, { x: new Date('2025-07-06'), y: 561.00 }, { x: new Date('2025-07-07'), y: 561.26 }, { x: new Date('2025-07-08'), y: 560.02 }, { x: new Date('2025-07-09'), y: 559.82 }, { x: new Date('2025-07-10'), y: 558.08 }, { x: new Date('2025-07-12'), y: 556.58 }, { x: new Date('2025-07-13'), y: 557.32 }, { x: new Date('2025-07-14'), y: 557.26 }, { x: new Date('2025-07-16'), y: 554.54 }, { x: new Date('2025-07-17'), y: 554.97 }, { x: new Date('2025-07-19'), y: 555.48 }, { x: new Date('2025-07-20'), y: 556.16 }, { x: new Date('2025-07-21'), y: 554.43 }, { x: new Date('2025-07-22'), y: 555.81 }, { x: new Date('2025-07-23'), y: 554.13 }, { x: new Date('2025-07-24'), y: 556.13 }, { x: new Date('2025-07-25'), y: 554.99 }, { x: new Date('2025-07-26'), y: 555.01 }, { x: new Date('2025-07-27'), y: 554.72 }, { x: new Date('2025-07-29'), y: 552.09 }, { x: new Date('2025-07-30'), y: 551.47 }, { x: new Date('2025-07-31'), y: 551.03 }, { x: new Date('2025-08-01'), y: 550.86 }, { x: new Date('2025-08-02'), y: 551.77 }, { x: new Date('2025-08-03'), y: 551.91 }, { x: new Date('2025-08-04'), y: 551.53 }, { x: new Date('2025-08-05'), y: 548.34 }, { x: new Date('2025-08-06'), y: 548.03 }, { x: new Date('2025-08-07'), y: 546.82 }, { x: new Date('2025-08-08'), y: 547.65 }, { x: new Date('2025-08-09'), y: 545.64 }, { x: new Date('2025-08-10'), y: 545.62 }, { x: new Date('2025-08-11'), y: 544.81 }, { x: new Date('2025-08-12'), y: 543.28 }, { x: new Date('2025-08-13'), y: 543.52 }, { x: new Date('2025-08-14'), y: 539.77 }, { x: new Date('2025-08-15'), y: 536.77 }, { x: new Date('2025-08-16'), y: 539.48 }, { x: new Date('2025-08-18'), y: 539.26 }, { x: new Date('2025-08-19'), y: 539.89 }, { x: new Date('2025-08-20'), y: 540.46 }, { x: new Date('2025-08-21'), y: 537.88 }, { x: new Date('2025-08-22'), y: 535.16 }, { x: new Date('2025-08-23'), y: 536.86 }, { x: new Date('2025-08-24'), y: 536.72 }, { x: new Date('2025-08-25'), y: 536.67 }, { x: new Date('2025-08-26'), y: 534.08 }, { x: new Date('2025-08-27'), y: 533.31 }, { x: new Date('2025-08-28'), y: 535.71 }, { x: new Date('2025-08-29'), y: 536.61 }, { x: new Date('2025-08-30'), y: 539.27 }, { x: new Date('2025-08-31'), y: 539.18 }]; 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);