const allData = { jual: [ { x: new Date('2025-12-13'), y: 2298000 }, { x: new Date('2025-12-15'), y: 2298000 }, { x: new Date('2025-12-16'), y: 2308000 }, { x: new Date('2025-12-17'), y: 2313000 }, { x: new Date('2025-12-18'), y: 2317000 }, { x: new Date('2025-12-19'), y: 2322000 }, { x: new Date('2025-12-20'), y: 2324000 }, { x: new Date('2025-12-22'), y: 2342000 }, { x: new Date('2025-12-23'), y: 2406000 }, { x: new Date('2025-12-24'), y: 2424000 }, { x: new Date('2025-12-25'), y: 2409000 }, { x: new Date('2025-12-26'), y: 2426000 }, { x: new Date('2025-12-29'), y: 2425000 }, { x: new Date('2025-12-30'), y: 2344000 }, { x: new Date('2025-12-31'), y: 2337000 }, { x: new Date('2026-01-02'), y: 2331000 }, { x: new Date('2026-01-03'), y: 2326000 }, { x: new Date('2026-01-04'), y: 2326000 }, { x: new Date('2026-01-05'), y: 2360000 }, { x: new Date('2026-01-06'), y: 2383000 }, { x: new Date('2026-01-07'), y: 2400000 }, { x: new Date('2026-01-08'), y: 2400000 }, { x: new Date('2026-01-09'), y: 2402000 }, { x: new Date('2026-01-10'), y: 2433000 }, { x: new Date('2026-01-11'), y: 2466000 }, { x: new Date('2026-01-13'), y: 2488000 }, { x: new Date('2026-01-14'), y: 2497000 }, { x: new Date('2026-01-15'), y: 2492000 }, { x: new Date('2026-01-16'), y: 2497000 }, { x: new Date('2026-01-17'), y: 2495000 }, { x: new Date('2026-01-19'), y: 2532000 }, { x: new Date('2026-01-20'), y: 2545000 }, { x: new Date('2026-01-21'), y: 2599000 }, { x: new Date('2026-01-22'), y: 2601000 }, { x: new Date('2026-01-23'), y: 2674000 }, { x: new Date('2026-01-24'), y: 2685000 }, { x: new Date('2026-01-26'), y: 2715000 }, { x: new Date('2026-01-27'), y: 2717000 }, { x: new Date('2026-01-28'), y: 2766000 }, { x: new Date('2026-01-29'), y: 2933000 }, { x: new Date('2026-01-30'), y: 2826000 }, { x: new Date('2026-01-31'), y: 2641000 }, { x: new Date('2026-02-02'), y: 2546000 }, { x: new Date('2026-02-03'), y: 2563000 }, { x: new Date('2026-02-04'), y: 2659000 }, { x: new Date('2026-02-05'), y: 2629000 }, { x: new Date('2026-02-06'), y: 2594000 }, { x: new Date('2026-02-07'), y: 2674000 }, { x: new Date('2026-02-09'), y: 2724000 }, { x: new Date('2026-02-10'), y: 2716000 }, { x: new Date('2026-02-11'), y: 2718000 } ], beli: [ { x: new Date('2025-12-13'), y: 2355000 }, { x: new Date('2025-12-15'), y: 2355000 }, { x: new Date('2025-12-16'), y: 2365000 }, { x: new Date('2025-12-17'), y: 2370000 }, { x: new Date('2025-12-18'), y: 2374000 }, { x: new Date('2025-12-19'), y: 2379000 }, { x: new Date('2025-12-20'), y: 2381000 }, { x: new Date('2025-12-22'), y: 2399000 }, { x: new Date('2025-12-23'), y: 2465000 }, { x: new Date('2025-12-24'), y: 2483000 }, { x: new Date('2025-12-25'), y: 2468000 }, { x: new Date('2025-12-26'), y: 2485000 }, { x: new Date('2025-12-29'), y: 2484000 }, { x: new Date('2025-12-30'), y: 2403000 }, { x: new Date('2025-12-31'), y: 2396000 }, { x: new Date('2026-01-02'), y: 2390000 }, { x: new Date('2026-01-03'), y: 2385000 }, { x: new Date('2026-01-04'), y: 2385000 }, { x: new Date('2026-01-05'), y: 2419000 }, { x: new Date('2026-01-06'), y: 2442000 }, { x: new Date('2026-01-07'), y: 2459000 }, { x: new Date('2026-01-08'), y: 2459000 }, { x: new Date('2026-01-09'), y: 2461000 }, { x: new Date('2026-01-10'), y: 2492000 }, { x: new Date('2026-01-11'), y: 2525000 }, { x: new Date('2026-01-13'), y: 2548000 }, { x: new Date('2026-01-14'), y: 2557000 }, { x: new Date('2026-01-15'), y: 2553000 }, { x: new Date('2026-01-16'), y: 2558000 }, { x: new Date('2026-01-17'), y: 2555000 }, { x: new Date('2026-01-19'), y: 2593000 }, { x: new Date('2026-01-20'), y: 2606000 }, { x: new Date('2026-01-21'), y: 2661000 }, { x: new Date('2026-01-22'), y: 2663000 }, { x: new Date('2026-01-23'), y: 2738000 }, { x: new Date('2026-01-24'), y: 2749000 }, { x: new Date('2026-01-26'), y: 2779000 }, { x: new Date('2026-01-27'), y: 2783000 }, { x: new Date('2026-01-28'), y: 2832000 }, { x: new Date('2026-01-29'), y: 3005000 }, { x: new Date('2026-01-30'), y: 2896000 }, { x: new Date('2026-01-31'), y: 2709000 }, { x: new Date('2026-02-02'), y: 2614000 }, { x: new Date('2026-02-03'), y: 2638000 }, { x: new Date('2026-02-04'), y: 2738000 }, { x: new Date('2026-02-05'), y: 2708000 }, { x: new Date('2026-02-06'), y: 2673000 }, { x: new Date('2026-02-07'), y: 2753000 }, { x: new Date('2026-02-09'), y: 2803000 }, { x: new Date('2026-02-10'), y: 2792000 }, { x: new Date('2026-02-11'), y: 2794000 } ] }; 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');