const allData = { jual: [ { x: new Date('2025-12-13'), y: 2295500 }, { x: new Date('2025-12-15'), y: 2313500 }, { x: new Date('2025-12-16'), y: 2323000 }, { x: new Date('2025-12-17'), y: 2307500 }, { x: new Date('2025-12-18'), y: 2328500 }, { x: new Date('2025-12-19'), y: 2328000 }, { x: new Date('2025-12-20'), y: 2325000 }, { x: new Date('2025-12-22'), y: 2325000 }, { x: new Date('2025-12-23'), y: 2386000 }, { x: new Date('2025-12-24'), y: 2404000 }, { x: new Date('2025-12-25'), y: 2402000 }, { x: new Date('2025-12-26'), y: 2402000 }, { x: new Date('2025-12-29'), y: 2402000 }, { x: new Date('2025-12-30'), y: 2366000 }, { x: new Date('2025-12-31'), y: 2376500 }, { x: new Date('2026-01-02'), y: 2347000 }, { x: new Date('2026-01-03'), y: 2357000 }, { x: new Date('2026-01-04'), y: 2357000 }, { x: new Date('2026-01-05'), y: 2353000 }, { x: new Date('2026-01-06'), y: 2376000 }, { x: new Date('2026-01-07'), y: 2409500 }, { x: new Date('2026-01-08'), y: 2416000 }, { x: new Date('2026-01-09'), y: 2408500 }, { x: new Date('2026-01-10'), y: 2420500 }, { x: new Date('2026-01-11'), y: 2443500 }, { x: new Date('2026-01-13'), y: 2496500 }, { x: new Date('2026-01-14'), y: 2498000 }, { x: new Date('2026-01-15'), y: 2511000 }, { x: new Date('2026-01-16'), y: 2502000 }, { x: new Date('2026-01-17'), y: 2501000 }, { x: new Date('2026-01-19'), y: 2541500 }, { x: new Date('2026-01-20'), y: 2548500 }, { x: new Date('2026-01-21'), y: 2590500 }, { x: new Date('2026-01-22'), y: 2620500 }, { x: new Date('2026-01-23'), y: 2709000 }, { x: new Date('2026-01-24'), y: 2717500 }, { x: new Date('2026-01-26'), y: 2771500 }, { x: new Date('2026-01-27'), y: 2756000 }, { x: new Date('2026-01-28'), y: 2796500 }, { x: new Date('2026-01-29'), y: 2940500 }, { x: new Date('2026-01-30'), y: 2890000 }, { x: new Date('2026-01-31'), y: 2665500 }, { x: new Date('2026-02-02'), y: 2537500 }, { x: new Date('2026-02-03'), y: 2580000 }, { x: new Date('2026-02-04'), y: 2722000 }, { x: new Date('2026-02-05'), y: 2691000 }, { x: new Date('2026-02-06'), y: 2582500 }, { x: new Date('2026-02-07'), y: 2718500 }, { x: new Date('2026-02-09'), y: 2771500 }, { x: new Date('2026-02-10'), y: 2766500 }, { x: new Date('2026-02-11'), y: 2749000 } ], beli: [ { x: new Date('2025-12-13'), y: 2368956 }, { x: new Date('2025-12-15'), y: 2387532 }, { x: new Date('2025-12-16'), y: 2397336 }, { x: new Date('2025-12-17'), y: 2381340 }, { x: new Date('2025-12-18'), y: 2403012 }, { x: new Date('2025-12-19'), y: 2402496 }, { x: new Date('2025-12-20'), y: 2399400 }, { x: new Date('2025-12-22'), y: 2399400 }, { x: new Date('2025-12-23'), y: 2462352 }, { x: new Date('2025-12-24'), y: 2480928 }, { x: new Date('2025-12-25'), y: 2478864 }, { x: new Date('2025-12-26'), y: 2478864 }, { x: new Date('2025-12-29'), y: 2478864 }, { x: new Date('2025-12-30'), y: 2441712 }, { x: new Date('2025-12-31'), y: 2452548 }, { x: new Date('2026-01-02'), y: 2422104 }, { x: new Date('2026-01-03'), y: 2432424 }, { x: new Date('2026-01-04'), y: 2432424 }, { x: new Date('2026-01-05'), y: 2435104 }, { x: new Date('2026-01-06'), y: 2452032 }, { x: new Date('2026-01-07'), y: 2486604 }, { x: new Date('2026-01-08'), y: 2493312 }, { x: new Date('2026-01-09'), y: 2485572 }, { x: new Date('2026-01-10'), y: 2497959 }, { x: new Date('2026-01-11'), y: 2505956 }, { x: new Date('2026-01-13'), y: 2576388 }, { x: new Date('2026-01-14'), y: 2577930 }, { x: new Date('2026-01-15'), y: 2591352 }, { x: new Date('2026-01-16'), y: 2582064 }, { x: new Date('2026-01-17'), y: 2581064 }, { x: new Date('2026-01-19'), y: 2622828 }, { x: new Date('2026-01-20'), y: 2630052 }, { x: new Date('2026-01-21'), y: 2673396 }, { x: new Date('2026-01-22'), y: 2704356 }, { x: new Date('2026-01-23'), y: 2795688 }, { x: new Date('2026-01-24'), y: 2804460 }, { x: new Date('2026-01-26'), y: 2860180 }, { x: new Date('2026-01-27'), y: 2844190 }, { x: new Date('2026-01-28'), y: 2885988 }, { x: new Date('2026-01-29'), y: 3034596 }, { x: new Date('2026-01-30'), y: 2982480 }, { x: new Date('2026-01-31'), y: 2753461 }, { x: new Date('2026-02-02'), y: 2644075 }, { x: new Date('2026-02-03'), y: 2688360 }, { x: new Date('2026-02-04'), y: 2836324 }, { x: new Date('2026-02-05'), y: 2777112 }, { x: new Date('2026-02-06'), y: 2690965 }, { x: new Date('2026-02-07'), y: 2805745 }, { x: new Date('2026-02-09'), y: 2860188 }, { x: new Date('2026-02-10'), y: 2834888 }, { x: new Date('2026-02-11'), y: 2817990 } ] }; const chartOptions = { chart: { type: 'area', height: '300', zoom: { enabled: false }, toolbar: { show: false }, offsetX: 0 }, colors: ['#008FFB', '#DFBD69'], dataLabels: { enabled: false }, stroke: { curve: 'smooth', width: 2 }, series: [], xaxis: { type: 'datetime', labels: { datetimeUTC: false }, min: undefined, max: undefined }, yaxis: { tickAmount: 4, labels: { style: { fontSize: '12px' }, offsetX: -15, formatter: function (value) { const text = value.toLocaleString('id-ID'); return text.length > 5 ? text.slice(0, 5) + '…' : text; } } }, grid: { padding: { left: -10, right: 0 } }, tooltip: { x: { format: 'dd MMM yyyy' }, y: { formatter: value => new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(value) } }, fill: { type: 'gradient', gradient: { shadeIntensity: 1, opacityFrom: 0.4, opacityTo: 0.05, stops: [0, 90, 100] } }, legend: { position: 'top', horizontalAlign: 'right' } }; const chart = new ApexCharts(document.querySelector("#chart"), chartOptions); chart.render(); function padIfTooFew(data, cutoff, now) { if (data.length === 1) { return [ { x: cutoff.getTime(), y: null }, ...data, { x: now.getTime(), y: null } ]; } return data; } function filterData(months) { const now = new Date(); let cutoff; if (months === 'all') { cutoff = new Date('2000-01-01'); } else { cutoff = new Date(); cutoff.setMonth(cutoff.getMonth() - parseInt(months)); } let filteredJual = allData.jual.filter(d => d.x >= cutoff.getTime()); let filteredBeli = allData.beli.filter(d => d.x >= cutoff.getTime()); filteredJual = padIfTooFew(filteredJual, cutoff, now); filteredBeli = padIfTooFew(filteredBeli, cutoff, now); chart.updateSeries([ { name: 'Jual', data: filteredJual }, { name: 'Beli', data: filteredBeli } ]); chart.updateOptions({ xaxis: { min: cutoff.getTime(), max: now.getTime() } }); } document.querySelectorAll(".filter-btn").forEach(btn => { btn.addEventListener("click", function () { document.querySelectorAll(".filter-btn").forEach(b => b.classList.remove("active")); this.classList.add("active"); const months = this.getAttribute("data-months"); if (months) { filterData(months); } }); }); // Initial load (1 Bulan) filterData('1');