const fullData = [ { x: new Date('2024-02-02'), y: 11733 }, { x: new Date('2024-02-05'), y: 11714 }, { x: new Date('2024-02-06'), y: 11692 }, { x: new Date('2024-02-07'), y: 11675 }, { x: new Date('2024-02-08'), y: 11653 }, { x: new Date('2024-02-09'), y: 11630 }, { x: new Date('2024-02-10'), y: 11597 }, { x: new Date('2024-02-12'), y: 11601 }, { x: new Date('2024-02-13'), y: 11575 }, { x: new Date('2024-02-14'), y: 11587 }, { x: new Date('2024-05-20'), y: 11874 }, { x: new Date('2024-08-01'), y: 12150 }, { x: new Date('2024-08-02'), y: 12163 }, { x: new Date('2024-08-05'), y: 12214 }, { x: new Date('2024-08-06'), y: 12220 }, { x: new Date('2024-08-07'), y: 12090 }, { x: new Date('2024-08-28'), y: 11881 }, { x: new Date('2024-08-29'), y: 11836 }, { x: new Date('2024-08-30'), y: 11885 }, { x: new Date('2024-09-02'), y: 11898 }, { x: new Date('2024-09-03'), y: 11902 }, { x: new Date('2024-09-04'), y: 11840 }, { x: new Date('2024-09-05'), y: 11828 }, { x: new Date('2024-09-05'), y: 11832 }, { x: new Date('2024-09-06'), y: 11822 }, { x: new Date('2024-09-07'), y: 11867 }, { x: new Date('2024-09-08'), y: 11867 }, { x: new Date('2024-09-09'), y: 11850 }, { x: new Date('2024-09-10'), y: 11815 }, { x: new Date('2024-09-19'), y: 11828 }, { x: new Date('2024-09-20'), y: 11698 }, { x: new Date('2024-09-23'), y: 11744 }, { x: new Date('2024-09-24'), y: 11768 }, { x: new Date('2024-09-25'), y: 11757 }, { x: new Date('2024-09-26'), y: 11800 }, { x: new Date('2024-09-27'), y: 11791 }, { x: new Date('2024-10-01'), y: 11820 }, { x: new Date('2024-10-02'), y: 11827 }, { x: new Date('2024-10-03'), y: 11898 }, { x: new Date('2024-10-04'), y: 11939 }, { x: new Date('2024-10-05'), y: 12020 }, { x: new Date('2024-10-07'), y: 12009 }, { x: new Date('2024-10-08'), y: 12042 }, { x: new Date('2024-10-10'), y: 12016 }, { x: new Date('2024-10-11'), y: 11997 }, { x: new Date('2024-10-12'), y: 11929 }, { x: new Date('2024-10-14'), y: 11910 }, { x: new Date('2024-10-15'), y: 11889 }, { x: new Date('2024-10-16'), y: 11879 }, { x: new Date('2024-10-17'), y: 11866 }, { x: new Date('2024-10-18'), y: 11808 }, { x: new Date('2024-10-19'), y: 11808 }, { x: new Date('2024-10-20'), y: 11808 }, { x: new Date('2024-10-21'), y: 11808 }, { x: new Date('2024-10-22'), y: 11831 }, { x: new Date('2024-10-23'), y: 11843 }, { x: new Date('2024-10-24'), y: 11827 }, { x: new Date('2024-10-25'), y: 11853 }, { x: new Date('2024-10-26'), y: 11888 }, { x: new Date('2024-10-27'), y: 11888 }, { x: new Date('2024-10-28'), y: 11815 }, { x: new Date('2024-10-29'), y: 11910 }, { x: new Date('2024-10-30'), y: 11900 }, { x: new Date('2024-10-31'), y: 11860 }, { x: new Date('2024-11-01'), y: 11915 }, { x: new Date('2024-11-02'), y: 11947 }, { x: new Date('2024-11-03'), y: 11947 }, { x: new Date('2024-11-04'), y: 11947 }, { x: new Date('2024-11-05'), y: 11973 }, { x: new Date('2024-11-06'), y: 11954 }, { x: new Date('2024-11-07'), y: 11873 }, { x: new Date('2024-11-08'), y: 11789 }, { x: new Date('2024-11-09'), y: 11811 }, { x: new Date('2024-11-10'), y: 11811 }, { x: new Date('2024-11-11'), y: 11809 }, { x: new Date('2024-11-12'), y: 11815 }, { x: new Date('2024-11-13'), y: 11817 }, { x: new Date('2024-11-14'), y: 11772 }, { x: new Date('2024-11-15'), y: 11867 }, { x: new Date('2024-11-16'), y: 11832 }, { x: new Date('2024-11-17'), y: 11832 }, { x: new Date('2024-11-18'), y: 11825 }, { x: new Date('2024-11-19'), y: 11836 }, { x: new Date('2024-11-21'), y: 11855 }, { x: new Date('2024-11-22'), y: 11829 }, { x: new Date('2024-11-23'), y: 11832 }, { x: new Date('2024-11-24'), y: 11832 }, { x: new Date('2024-11-26'), y: 11766 }, { x: new Date('2024-11-27'), y: 11818 }, { x: new Date('2024-11-28'), y: 11816 }, { x: new Date('2024-11-29'), y: 11830 }, { x: new Date('2024-12-01'), y: 11821 }, { x: new Date('2024-12-02'), y: 11800 }, { x: new Date('2024-12-03'), y: 11837 }, { x: new Date('2024-12-04'), y: 11855 }, { x: new Date('2024-12-06'), y: 11835 }, { x: new Date('2024-12-07'), y: 11815 }, { x: new Date('2024-12-08'), y: 11815 }, { x: new Date('2024-12-09'), y: 11815 }, { x: new Date('2024-12-10'), y: 11826 }, { x: new Date('2024-12-11'), y: 11864 }, { x: new Date('2024-12-12'), y: 11873 }, { x: new Date('2024-12-13'), y: 11839 }, { x: new Date('2024-12-14'), y: 11883 }, { x: new Date('2024-12-15'), y: 11883 }, { x: new Date('2024-12-16'), y: 11890 }, { x: new Date('2024-12-17'), y: 11882 }, { x: new Date('2024-12-18'), y: 11880 }, { x: new Date('2024-12-19'), y: 11956 }, { x: new Date('2024-12-20'), y: 11995 }, { x: new Date('2024-12-22'), y: 11936 }, { x: new Date('2024-12-23'), y: 11936 }, { x: new Date('2024-12-24'), y: 11960 }, { x: new Date('2024-12-25'), y: 11923 }, { x: new Date('2024-12-27'), y: 11942 }, { x: new Date('2024-12-30'), y: 11955 }, { x: new Date('2024-12-31'), y: 11878 }, { x: new Date('2025-01-02'), y: 11921 }, { x: new Date('2025-01-03'), y: 11874 }, { x: new Date('2025-01-04'), y: 11818 }, { x: new Date('2025-01-06'), y: 11818 }, { x: new Date('2025-01-15'), y: 11914 }, { x: new Date('2025-01-16'), y: 11991 }, { x: new Date('2025-01-17'), y: 12009 }, { x: new Date('2025-01-19'), y: 11972 }, { x: new Date('2025-01-20'), y: 11966 }, { x: new Date('2025-01-21'), y: 12038 }, { x: new Date('2025-01-22'), y: 12069 }, { x: new Date('2025-01-23'), y: 12009 }, { x: new Date('2025-01-24'), y: 11976 }, { x: new Date('2025-01-25'), y: 12015 }, { x: new Date('2025-01-26'), y: 12015 }, { x: new Date('2025-01-27'), y: 12002 }, { x: new Date('2025-01-28'), y: 11997 }, { x: new Date('2025-01-29'), y: 11997 }, { x: new Date('2025-01-31'), y: 12033 }, { x: new Date('2025-02-01'), y: 12037 }, { x: new Date('2025-02-03'), y: 11954 }, { x: new Date('2025-02-04'), y: 12005 }, { x: new Date('2025-02-06'), y: 12072 }, { x: new Date('2025-02-07'), y: 12056 }, { x: new Date('2025-02-08'), y: 12031 }, { x: new Date('2025-02-09'), y: 12038 }, { x: new Date('2025-02-10'), y: 11996 }, { x: new Date('2025-02-11'), y: 11996 }, { x: new Date('2025-02-12'), y: 12040 }, { x: new Date('2025-02-13'), y: 12105 }, { x: new Date('2025-02-14'), y: 12149 }, { x: new Date('2025-02-17'), y: 12127 }, { x: new Date('2025-02-18'), y: 12091 }, { x: new Date('2025-02-19'), y: 12142 }, { x: new Date('2025-02-20'), y: 12173 }, { x: new Date('2025-02-24'), y: 12203 }, { x: new Date('2025-02-25'), y: 12163 }, { x: new Date('2025-02-26'), y: 12220 }, { x: new Date('2025-02-27'), y: 12206 }, { x: new Date('2025-02-28'), y: 12203 }, { x: new Date('2025-03-01'), y: 12279 }, { x: new Date('2025-03-02'), y: 12280 }, { x: new Date('2025-03-03'), y: 12277 }, { x: new Date('2025-03-04'), y: 12212 }, { x: new Date('2025-03-06'), y: 12245 }, { x: new Date('2025-03-07'), y: 12244 }, { x: new Date('2025-03-08'), y: 12252 }, { x: new Date('2025-03-10'), y: 12240 }, { x: new Date('2025-03-11'), y: 12280 }, { x: new Date('2025-03-12'), y: 12333.05 }, { x: new Date('2025-03-13'), y: 12317.65 }, { x: new Date('2025-03-14'), y: 12280.74 }, { x: new Date('2025-03-15'), y: 12253.00 }, { x: new Date('2025-03-16'), y: 12251.64 }, { x: new Date('2025-03-17'), y: 12251.64 }, { x: new Date('2025-03-18'), y: 12263.45 }, { x: new Date('2025-03-19'), y: 12358.47 }, { x: new Date('2025-03-20'), y: 12393.14 }, { x: new Date('2025-03-21'), y: 12347.74 }, { x: new Date('2025-03-22'), y: 12355.27 }, { x: new Date('2025-03-23'), y: 12356.10 }, { x: new Date('2025-03-24'), y: 12356.15 }, { x: new Date('2025-03-25'), y: 12356.15 }, { x: new Date('2025-03-26'), y: 12423.34 }, { x: new Date('2025-03-27'), y: 12386.59 }, { x: new Date('2025-03-28'), y: 12383.37 }, { x: new Date('2025-03-30'), y: 12369.22 }, { x: new Date('2025-03-31'), y: 12343.35 }, { x: new Date('2025-04-01'), y: 12334.60 }, { x: new Date('2025-04-02'), y: 12311.21 }, { x: new Date('2025-04-03'), y: 12366.32 }, { x: new Date('2025-04-04'), y: 12424.80 }, { x: new Date('2025-04-05'), y: 12311.64 }, { x: new Date('2025-04-06'), y: 12327.34 }, { x: new Date('2025-04-07'), y: 12265.28 }, { x: new Date('2025-04-08'), y: 12237.26 }, { x: new Date('2025-04-09'), y: 12498.50 }, { x: new Date('2025-04-10'), y: 12545.31 }, { x: new Date('2025-04-11'), y: 12630.98 }, { x: new Date('2025-04-12'), y: 12720.17 }, { x: new Date('2025-04-13'), y: 12729.20 }, { x: new Date('2025-04-14'), y: 12722.73 }, { x: new Date('2025-04-15'), y: 12740.57 }, { x: new Date('2025-04-16'), y: 12761.54 }, { x: new Date('2025-04-17'), y: 12797.15 }, { x: new Date('2025-04-18'), y: 12853.27 }, { x: new Date('2025-04-19'), y: 12841.23 }, { x: new Date('2025-04-20'), y: 12842.38 }, { x: new Date('2025-04-21'), y: 12874.58 }, { x: new Date('2025-04-22'), y: 12897.40 }, { x: new Date('2025-04-23'), y: 12862.92 }, { x: new Date('2025-04-24'), y: 12852.18 }, { x: new Date('2025-04-26'), y: 12825.08 }, { x: new Date('2025-04-27'), y: 12823.99 }, { x: new Date('2025-04-28'), y: 12807.17 }, { x: new Date('2025-05-02'), y: 12692.22 }, { x: new Date('2025-05-05'), y: 12674.55 }, { x: new Date('2025-05-06'), y: 12674.55 }, { x: new Date('2025-05-08'), y: 12748.67 }, { x: new Date('2025-05-09'), y: 12718.86 }, { x: new Date('2025-05-10'), y: 12750.43 }, { x: new Date('2025-05-11'), y: 12744.82 }, { x: new Date('2025-05-12'), y: 12739.56 }, { x: new Date('2025-05-13'), y: 12660.83 }, { x: new Date('2025-05-14'), y: 12664.50 }, { x: new Date('2025-05-15'), y: 12751.02 }, { x: new Date('2025-05-16'), y: 12712.54 }, { x: new Date('2025-05-17'), y: 12657.89 }, { x: new Date('2025-05-19'), y: 12665.56 }, { x: new Date('2025-05-20'), y: 12699.05 }, { x: new Date('2025-05-21'), y: 12668.77 }, { x: new Date('2025-05-22'), y: 12724.32 }, { x: new Date('2025-05-24'), y: 12614.34 }, { x: new Date('2025-05-26'), y: 12616.98 }, { x: new Date('2025-05-27'), y: 12621.25 }, { x: new Date('2025-06-04'), y: 12655.71 }, { x: new Date('2025-06-05'), y: 12655.65 }, { x: new Date('2025-06-06'), y: 12654.37 }, { x: new Date('2025-06-07'), y: 12645.41 }, { x: new Date('2025-06-08'), y: 12649.20 }, { x: new Date('2025-06-10'), y: 12662.33 }, { x: new Date('2025-06-11'), y: 12650.44 }, { x: new Date('2025-06-12'), y: 12656.90 }, { x: new Date('2025-06-13'), y: 12682.58 }, { x: new Date('2025-06-14'), y: 12736.24 }, { x: new Date('2025-06-15'), y: 12727.68 }, { x: new Date('2025-06-16'), y: 12705.60 }, { x: new Date('2025-06-17'), y: 12725.64 }, { x: new Date('2025-06-18'), y: 12642.90 }, { x: new Date('2025-06-20'), y: 12716.08 }, { x: new Date('2025-06-21'), y: 12734.90 }, { x: new Date('2025-06-22'), y: 12738.14 }, { x: new Date('2025-06-23'), y: 12736.80 }, { x: new Date('2025-06-24'), y: 12824.56 }, { x: new Date('2025-06-25'), y: 12763.32 }, { x: new Date('2025-06-26'), y: 12754.75 }, { x: new Date('2025-06-27'), y: 12728.71 }, { x: new Date('2025-06-28'), y: 12720.46 }, { x: new Date('2025-06-29'), y: 12714.60 }, { x: new Date('2025-06-30'), y: 12706.11 }, { x: new Date('2025-07-01'), y: 12751.24 }, { x: new Date('2025-07-02'), y: 12738.58 }, { x: new Date('2025-07-04'), y: 12706.87 }, { x: new Date('2025-07-05'), y: 12706.97 }, { x: new Date('2025-07-06'), y: 12707.20 }, { x: new Date('2025-07-07'), y: 12701.77 }, { x: new Date('2025-07-08'), y: 12699.70 }, { x: new Date('2025-07-09'), y: 12696.11 }, { x: new Date('2025-07-10'), y: 12699.83 }, { x: new Date('2025-07-12'), y: 12682.49 }, { x: new Date('2025-07-13'), y: 12675.23 }, { x: new Date('2025-07-14'), y: 12675.33 }, { x: new Date('2025-07-16'), y: 12681.27 }, { x: new Date('2025-07-17'), y: 12691.64 }, { x: new Date('2025-07-19'), y: 12698.21 }, { x: new Date('2025-07-20'), y: 12696.32 }, { x: new Date('2025-07-21'), y: 12685.20 }, { x: new Date('2025-07-22'), y: 12732.56 }, { x: new Date('2025-07-23'), y: 12725.26 }, { x: new Date('2025-07-24'), y: 12734.77 }, { x: new Date('2025-07-25'), y: 12740.46 }, { x: new Date('2025-07-26'), y: 12740.09 }, { x: new Date('2025-07-27'), y: 12742.18 }, { x: new Date('2025-07-29'), y: 12716.51 }, { x: new Date('2025-07-30'), y: 12730.96 }, { x: new Date('2025-07-31'), y: 12696.98 }, { x: new Date('2025-08-01'), y: 12700.56 }, { x: new Date('2025-08-02'), y: 12739.00 }, { x: new Date('2025-08-03'), y: 12732.87 }, { x: new Date('2025-08-04'), y: 12762.92 }, { x: new Date('2025-08-05'), y: 12725.61 }, { x: new Date('2025-08-06'), y: 12726.16 }, { x: new Date('2025-08-07'), y: 12722.93 }, { x: new Date('2025-08-08'), y: 12714.24 }, { x: new Date('2025-08-09'), y: 12696.46 }, { x: new Date('2025-08-10'), y: 12688.15 }, { x: new Date('2025-08-11'), y: 12669.07 }, { x: new Date('2025-08-12'), y: 12640.18 }, { x: new Date('2025-08-13'), y: 12663.37 }, { x: new Date('2025-08-14'), y: 12639.03 }, { x: new Date('2025-08-15'), y: 12558.46 }, { x: new Date('2025-08-16'), y: 12576.44 }, { x: new Date('2025-08-18'), y: 12595.48 }, { x: new Date('2025-08-19'), y: 12599.52 }, { x: new Date('2025-08-20'), y: 12662.45 }, { x: new Date('2025-08-21'), y: 12671.77 }, { x: new Date('2025-08-22'), y: 12666.56 }, { x: new Date('2025-08-23'), y: 12714.28 }, { x: new Date('2025-08-24'), y: 12709.85 }, { x: new Date('2025-08-25'), y: 12730.89 }, { x: new Date('2025-08-26'), y: 12660.20 }, { x: new Date('2025-08-27'), y: 12679.29 }, { x: new Date('2025-08-28'), y: 12744.49 }, { x: new Date('2025-08-29'), y: 12741.85 }, { x: new Date('2025-08-30'), y: 12855.53 }, { x: new Date('2025-08-31'), y: 12845.66 }]; 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);