const fullData = [ { x: new Date('2024-02-02'), y: 2006 }, { x: new Date('2024-02-05'), y: 2011 }, { x: new Date('2024-02-06'), y: 2012 }, { x: new Date('2024-02-07'), y: 2005 }, { x: new Date('2024-02-08'), y: 2001 }, { x: new Date('2024-02-09'), y: 2002 }, { x: new Date('2024-02-10'), y: 1996 }, { x: new Date('2024-02-12'), y: 1996 }, { x: new Date('2024-02-13'), y: 1992 }, { x: new Date('2024-02-14'), y: 2004 }, { x: new Date('2024-05-20'), y: 2047 }, { x: new Date('2024-08-01'), y: 2078 }, { x: new Date('2024-08-02'), y: 2078 }, { x: new Date('2024-08-05'), y: 2077 }, { x: new Date('2024-08-06'), y: 2077 }, { x: new Date('2024-08-07'), y: 2057 }, { x: new Date('2024-08-28'), y: 1986 }, { x: new Date('2024-08-29'), y: 1974 }, { x: new Date('2024-08-30'), y: 1986 }, { x: new Date('2024-09-02'), y: 1993 }, { x: new Date('2024-09-03'), y: 1997 }, { x: new Date('2024-09-04'), y: 1985 }, { x: new Date('2024-09-05'), y: 1976 }, { x: new Date('2024-09-05'), y: 1977 }, { x: new Date('2024-09-06'), y: 1970 }, { x: new Date('2024-09-07'), y: 1982 }, { x: new Date('2024-09-08'), y: 1982 }, { x: new Date('2024-09-09'), y: 1979 }, { x: new Date('2024-09-10'), y: 1979 }, { x: new Date('2024-09-19'), y: 1972 }, { x: new Date('2024-09-20'), y: 1938 }, { x: new Date('2024-09-23'), y: 1945 }, { x: new Date('2024-09-24'), y: 1950 }, { x: new Date('2024-09-25'), y: 1936 }, { x: new Date('2024-09-26'), y: 1952 }, { x: new Date('2024-09-27'), y: 1947 }, { x: new Date('2024-10-01'), y: 1955 }, { x: new Date('2024-10-02'), y: 1959 }, { x: new Date('2024-10-03'), y: 1984 }, { x: new Date('2024-10-04'), y: 1994 }, { x: new Date('2024-10-05'), y: 2017 }, { x: new Date('2024-10-07'), y: 2017 }, { x: new Date('2024-10-08'), y: 2021 }, { x: new Date('2024-10-10'), y: 2023 }, { x: new Date('2024-10-11'), y: 2016 }, { x: new Date('2024-10-12'), y: 2004 }, { x: new Date('2024-10-14'), y: 2002 }, { x: new Date('2024-10-15'), y: 2005 }, { x: new Date('2024-10-16'), y: 2003 }, { x: new Date('2024-10-17'), y: 2001 }, { x: new Date('2024-10-18'), y: 1997 }, { x: new Date('2024-10-19'), y: 1991 }, { x: new Date('2024-10-20'), y: 1991 }, { x: new Date('2024-10-21'), y: 1991 }, { x: new Date('2024-10-22'), y: 2001 }, { x: new Date('2024-10-23'), y: 2006 }, { x: new Date('2024-10-24'), y: 2014 }, { x: new Date('2024-10-25'), y: 2012 }, { x: new Date('2024-10-26'), y: 2021 }, { x: new Date('2024-10-27'), y: 2021 }, { x: new Date('2024-10-28'), y: 2012 }, { x: new Date('2024-10-29'), y: 2026 }, { x: new Date('2024-10-30'), y: 2026 }, { x: new Date('2024-10-31'), y: 2018 }, { x: new Date('2024-11-01'), y: 2022 }, { x: new Date('2024-11-02'), y: 2036 }, { x: new Date('2024-11-03'), y: 2036 }, { x: new Date('2024-11-04'), y: 2036 }, { x: new Date('2024-11-05'), y: 2028 }, { x: new Date('2024-11-06'), y: 2022 }, { x: new Date('2024-11-07'), y: 2035 }, { x: new Date('2024-11-08'), y: 2003 }, { x: new Date('2024-11-09'), y: 2012 }, { x: new Date('2024-11-10'), y: 2012 }, { x: new Date('2024-11-11'), y: 2015 }, { x: new Date('2024-11-12'), y: 2028 }, { x: new Date('2024-11-13'), y: 2034 }, { x: new Date('2024-11-14'), y: 2032 }, { x: new Date('2024-11-15'), y: 2053 }, { x: new Date('2024-11-16'), y: 2042 }, { x: new Date('2024-11-17'), y: 2042 }, { x: new Date('2024-11-18'), y: 2036 }, { x: new Date('2024-11-19'), y: 2036 }, { x: new Date('2024-11-21'), y: 2048 }, { x: new Date('2024-11-22'), y: 2045 }, { x: new Date('2024-11-23'), y: 2046 }, { x: new Date('2024-11-24'), y: 2046 }, { x: new Date('2024-11-26'), y: 2040 }, { x: new Date('2024-11-27'), y: 2046 }, { x: new Date('2024-11-28'), y: 2037 }, { x: new Date('2024-11-29'), y: 2036 }, { x: new Date('2024-12-01'), y: 2034 }, { x: new Date('2024-12-02'), y: 2034 }, { x: new Date('2024-12-03'), y: 2048 }, { x: new Date('2024-12-04'), y: 2048 }, { x: new Date('2024-12-06'), y: 2036 }, { x: new Date('2024-12-07'), y: 2039 }, { x: new Date('2024-12-08'), y: 2039 }, { x: new Date('2024-12-09'), y: 2039 }, { x: new Date('2024-12-10'), y: 2039 }, { x: new Date('2024-12-11'), y: 2047 }, { x: new Date('2024-12-12'), y: 2051 }, { x: new Date('2024-12-13'), y: 2051 }, { x: new Date('2024-12-14'), y: 2061 }, { x: new Date('2024-12-15'), y: 2061 }, { x: new Date('2024-12-16'), y: 2061 }, { x: new Date('2024-12-17'), y: 2062 }, { x: new Date('2024-12-18'), y: 2070 }, { x: new Date('2024-12-19'), y: 2093 }, { x: new Date('2024-12-20'), y: 2103 }, { x: new Date('2024-12-22'), y: 2079 }, { x: new Date('2024-12-23'), y: 2079 }, { x: new Date('2024-12-24'), y: 2089 }, { x: new Date('2024-12-25'), y: 2087 }, { x: new Date('2024-12-27'), y: 2089 }, { x: new Date('2024-12-30'), y: 2091 }, { x: new Date('2024-12-31'), y: 2078 }, { x: new Date('2025-01-02'), y: 2089 }, { x: new Date('2025-01-03'), y: 2088 }, { x: new Date('2025-01-04'), y: 2082 }, { x: new Date('2025-01-06'), y: 2082 }, { x: new Date('2025-01-15'), y: 2093 }, { x: new Date('2025-01-16'), y: 2104 }, { x: new Date('2025-01-17'), y: 2107 }, { x: new Date('2025-01-19'), y: 2104 }, { x: new Date('2025-01-20'), y: 2102 }, { x: new Date('2025-01-21'), y: 2095 }, { x: new Date('2025-01-22'), y: 2096 }, { x: new Date('2025-01-23'), y: 2090 }, { x: new Date('2025-01-24'), y: 2084 }, { x: new Date('2025-01-25'), y: 2076 }, { x: new Date('2025-01-26'), y: 2076 }, { x: new Date('2025-01-27'), y: 2076 }, { x: new Date('2025-01-28'), y: 2082 }, { x: new Date('2025-01-29'), y: 2080 }, { x: new Date('2025-01-31'), y: 2089 }, { x: new Date('2025-02-01'), y: 2098 }, { x: new Date('2025-02-03'), y: 2098 }, { x: new Date('2025-02-04'), y: 2095 }, { x: new Date('2025-02-06'), y: 2089 }, { x: new Date('2025-02-07'), y: 2095 }, { x: new Date('2025-02-08'), y: 2089 }, { x: new Date('2025-02-09'), y: 2089 }, { x: new Date('2025-02-10'), y: 2087 }, { x: new Date('2025-02-11'), y: 2087 }, { x: new Date('2025-02-12'), y: 2095 }, { x: new Date('2025-02-13'), y: 2103 }, { x: new Date('2025-02-14'), y: 2101 }, { x: new Date('2025-02-17'), y: 2087 }, { x: new Date('2025-02-18'), y: 2084 }, { x: new Date('2025-02-19'), y: 2095 }, { x: new Date('2025-02-20'), y: 2101 }, { x: new Date('2025-02-24'), y: 2099 }, { x: new Date('2025-02-25'), y: 2093 }, { x: new Date('2025-02-26'), y: 2105 }, { x: new Date('2025-02-27'), y: 2102 }, { x: new Date('2025-02-28'), y: 2113 }, { x: new Date('2025-03-01'), y: 2131 }, { x: new Date('2025-03-02'), y: 2130 }, { x: new Date('2025-03-03'), y: 2129 }, { x: new Date('2025-03-04'), y: 2114 }, { x: new Date('2025-03-06'), y: 2101 }, { x: new Date('2025-03-07'), y: 2096 }, { x: new Date('2025-03-08'), y: 2097 }, { x: new Date('2025-03-10'), y: 2094 }, { x: new Date('2025-03-11'), y: 2106 }, { x: new Date('2025-03-12'), y: 2112.88 }, { x: new Date('2025-03-13'), y: 2113.60 }, { x: new Date('2025-03-14'), y: 2111.34 }, { x: new Date('2025-03-15'), y: 2103.54 }, { x: new Date('2025-03-16'), y: 2103.67 }, { x: new Date('2025-03-17'), y: 2103.67 }, { x: new Date('2025-03-18'), y: 2104.41 }, { x: new Date('2025-03-19'), y: 2117.72 }, { x: new Date('2025-03-20'), y: 2124.61 }, { x: new Date('2025-03-21'), y: 2121.86 }, { x: new Date('2025-03-22'), y: 2122.70 }, { x: new Date('2025-03-23'), y: 2122.81 }, { x: new Date('2025-03-24'), y: 2122.60 }, { x: new Date('2025-03-25'), y: 2122.60 }, { x: new Date('2025-03-26'), y: 2135.04 }, { x: new Date('2025-03-27'), y: 2133.77 }, { x: new Date('2025-03-28'), y: 2133.31 }, { x: new Date('2025-03-30'), y: 2132.93 }, { x: new Date('2025-03-31'), y: 2130.58 }, { x: new Date('2025-04-01'), y: 2129.40 }, { x: new Date('2025-04-02'), y: 2130.06 }, { x: new Date('2025-04-03'), y: 2135.47 }, { x: new Date('2025-04-04'), y: 2132.83 }, { x: new Date('2025-04-05'), y: 2127.00 }, { x: new Date('2025-04-06'), y: 2127.97 }, { x: new Date('2025-04-07'), y: 2121.76 }, { x: new Date('2025-04-08'), y: 2127.30 }, { x: new Date('2025-04-09'), y: 2173.54 }, { x: new Date('2025-04-10'), y: 2174.97 }, { x: new Date('2025-04-11'), y: 2169.89 }, { x: new Date('2025-04-12'), y: 2164.02 }, { x: new Date('2025-04-13'), y: 2165.50 }, { x: new Date('2025-04-14'), y: 2165.78 }, { x: new Date('2025-04-15'), y: 2161.91 }, { x: new Date('2025-04-16'), y: 2165.18 }, { x: new Date('2025-04-17'), y: 2163.97 }, { x: new Date('2025-04-18'), y: 2171.35 }, { x: new Date('2025-04-19'), y: 2169.84 }, { x: new Date('2025-04-20'), y: 2170.10 }, { x: new Date('2025-04-21'), y: 2169.36 }, { x: new Date('2025-04-22'), y: 2168.60 }, { x: new Date('2025-04-23'), y: 2172.77 }, { x: new Date('2025-04-24'), y: 2175.50 }, { x: new Date('2025-04-26'), y: 2173.29 }, { x: new Date('2025-04-27'), y: 2173.11 }, { x: new Date('2025-04-28'), y: 2171.21 }, { x: new Date('2025-05-02'), y: 2144.17 }, { x: new Date('2025-05-05'), y: 2120.81 }, { x: new Date('2025-05-06'), y: 2120.81 }, { x: new Date('2025-05-08'), y: 2119.83 }, { x: new Date('2025-05-09'), y: 2124.97 }, { x: new Date('2025-05-10'), y: 2127.39 }, { x: new Date('2025-05-11'), y: 2126.45 }, { x: new Date('2025-05-12'), y: 2125.04 }, { x: new Date('2025-05-13'), y: 2121.46 }, { x: new Date('2025-05-14'), y: 2119.33 }, { x: new Date('2025-05-15'), y: 2123.32 }, { x: new Date('2025-05-16'), y: 2113.15 }, { x: new Date('2025-05-17'), y: 2104.55 }, { x: new Date('2025-05-19'), y: 2104.87 }, { x: new Date('2025-05-20'), y: 2102.36 }, { x: new Date('2025-05-21'), y: 2096.47 }, { x: new Date('2025-05-22'), y: 2095.54 }, { x: new Date('2025-05-24'), y: 2070.16 }, { x: new Date('2025-05-26'), y: 2068.48 }, { x: new Date('2025-05-27'), y: 2068.67 }, { x: new Date('2025-06-04'), y: 2079.18 }, { x: new Date('2025-06-05'), y: 2076.22 }, { x: new Date('2025-06-06'), y: 2073.42 }, { x: new Date('2025-06-07'), y: 2076.10 }, { x: new Date('2025-06-08'), y: 2076.03 }, { x: new Date('2025-06-10'), y: 2074.55 }, { x: new Date('2025-06-11'), y: 2073.11 }, { x: new Date('2025-06-12'), y: 2072.34 }, { x: new Date('2025-06-13'), y: 2066.55 }, { x: new Date('2025-06-14'), y: 2080.50 }, { x: new Date('2025-06-15'), y: 2079.34 }, { x: new Date('2025-06-16'), y: 2076.72 }, { x: new Date('2025-06-17'), y: 2075.39 }, { x: new Date('2025-06-18'), y: 2070.78 }, { x: new Date('2025-06-20'), y: 2085.03 }, { x: new Date('2025-06-21'), y: 2086.25 }, { x: new Date('2025-06-22'), y: 2086.74 }, { x: new Date('2025-06-23'), y: 2088.21 }, { x: new Date('2025-06-24'), y: 2103.85 }, { x: new Date('2025-06-25'), y: 2081.20 }, { x: new Date('2025-06-26'), y: 2078.53 }, { x: new Date('2025-06-27'), y: 2066.91 }, { x: new Date('2025-06-28'), y: 2067.82 }, { x: new Date('2025-06-29'), y: 2066.82 }, { x: new Date('2025-06-30'), y: 2065.16 }, { x: new Date('2025-07-01'), y: 2068.10 }, { x: new Date('2025-07-02'), y: 2063.82 }, { x: new Date('2025-07-04'), y: 2062.51 }, { x: new Date('2025-07-05'), y: 2062.68 }, { x: new Date('2025-07-06'), y: 2062.66 }, { x: new Date('2025-07-07'), y: 2061.83 }, { x: new Date('2025-07-08'), y: 2069.12 }, { x: new Date('2025-07-09'), y: 2069.52 }, { x: new Date('2025-07-10'), y: 2071.61 }, { x: new Date('2025-07-12'), y: 2068.63 }, { x: new Date('2025-07-13'), y: 2067.59 }, { x: new Date('2025-07-14'), y: 2067.60 }, { x: new Date('2025-07-16'), y: 2073.86 }, { x: new Date('2025-07-17'), y: 2076.12 }, { x: new Date('2025-07-19'), y: 2077.77 }, { x: new Date('2025-07-20'), y: 2077.33 }, { x: new Date('2025-07-21'), y: 2075.94 }, { x: new Date('2025-07-22'), y: 2077.65 }, { x: new Date('2025-07-23'), y: 2074.89 }, { x: new Date('2025-07-24'), y: 2072.00 }, { x: new Date('2025-07-25'), y: 2072.73 }, { x: new Date('2025-07-26'), y: 2078.87 }, { x: new Date('2025-07-27'), y: 2079.04 }, { x: new Date('2025-07-29'), y: 2082.37 }, { x: new Date('2025-07-30'), y: 2089.17 }, { x: new Date('2025-07-31'), y: 2090.53 }, { x: new Date('2025-08-01'), y: 2099.14 }, { x: new Date('2025-08-02'), y: 2098.47 }, { x: new Date('2025-08-03'), y: 2099.58 }, { x: new Date('2025-08-04'), y: 2100.58 }, { x: new Date('2025-08-05'), y: 2086.83 }, { x: new Date('2025-08-06'), y: 2088.17 }, { x: new Date('2025-08-07'), y: 2084.16 }, { x: new Date('2025-08-08'), y: 2079.30 }, { x: new Date('2025-08-09'), y: 2078.61 }, { x: new Date('2025-08-10'), y: 2077.20 }, { x: new Date('2025-08-11'), y: 2074.13 }, { x: new Date('2025-08-12'), y: 2071.54 }, { x: new Date('2025-08-13'), y: 2072.29 }, { x: new Date('2025-08-14'), y: 2059.16 }, { x: new Date('2025-08-15'), y: 2050.88 }, { x: new Date('2025-08-16'), y: 2060.12 }, { x: new Date('2025-08-18'), y: 2064.82 }, { x: new Date('2025-08-19'), y: 2071.70 }, { x: new Date('2025-08-20'), y: 2084.88 }, { x: new Date('2025-08-21'), y: 2084.55 }, { x: new Date('2025-08-22'), y: 2088.22 }, { x: new Date('2025-08-23'), y: 2089.59 }, { x: new Date('2025-08-24'), y: 2090.23 }, { x: new Date('2025-08-25'), y: 2091.75 }, { x: new Date('2025-08-26'), y: 2081.36 }, { x: new Date('2025-08-27'), y: 2090.24 }, { x: new Date('2025-08-28'), y: 2107.33 }, { x: new Date('2025-08-29'), y: 2097.34 }, { x: new Date('2025-08-30'), y: 2117.61 }, { x: new Date('2025-08-31'), y: 2116.30 }]; 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);