const allData = { jual: [ { x: new Date('2025-12-13'), y: 2317362 }, { x: new Date('2025-12-15'), y: 2321822 }, { x: new Date('2025-12-16'), y: 2323993 }, { x: new Date('2025-12-17'), y: 2342472 }, { x: new Date('2025-12-18'), y: 2341426 }, { x: new Date('2025-12-19'), y: 2340351 }, { x: new Date('2025-12-20'), y: 2346749 }, { x: new Date('2025-12-22'), y: 2367538 }, { x: new Date('2025-12-23'), y: 2427788 }, { x: new Date('2025-12-24'), y: 2446723 }, { x: new Date('2025-12-25'), y: 2427334 }, { x: new Date('2025-12-26'), y: 2452153 }, { x: new Date('2025-12-29'), y: 2443402 }, { x: new Date('2025-12-30'), y: 2358191 }, { x: new Date('2025-12-31'), y: 2352131 }, { x: new Date('2026-01-02'), y: 2352573 }, { x: new Date('2026-01-03'), y: 2344312 }, { x: new Date('2026-01-04'), y: 2344312 }, { x: new Date('2026-01-05'), y: 2380142 }, { x: new Date('2026-01-06'), y: 2406741 }, { x: new Date('2026-01-07'), y: 2437175 }, { x: new Date('2026-01-08'), y: 2414740 }, { x: new Date('2026-01-09'), y: 2429395 }, { x: new Date('2026-01-10'), y: 2459388 }, { x: new Date('2026-01-11'), y: 2503294 }, { x: new Date('2026-01-13'), y: 2504859 }, { x: new Date('2026-01-14'), y: 2516016 }, { x: new Date('2026-01-15'), y: 2518679 }, { x: new Date('2026-01-16'), y: 2514117 }, { x: new Date('2026-01-17'), y: 2516495 }, { x: new Date('2026-01-19'), y: 2559185 }, { x: new Date('2026-01-20'), y: 2556028 }, { x: new Date('2026-01-21'), y: 2627608 }, { x: new Date('2026-01-22'), y: 2623756 }, { x: new Date('2026-01-23'), y: 2703448 }, { x: new Date('2026-01-24'), y: 2704480 }, { x: new Date('2026-01-26'), y: 2735519 }, { x: new Date('2026-01-27'), y: 2725141 }, { x: new Date('2026-01-28'), y: 2791883 }, { x: new Date('2026-01-29'), y: 2935110 }, { x: new Date('2026-01-30'), y: 2935110 }, { x: new Date('2026-01-31'), y: 2653131 }, { x: new Date('2026-02-02'), y: 2581859 }, { x: new Date('2026-02-03'), y: 2591549 }, { x: new Date('2026-02-04'), y: 2716544 }, { x: new Date('2026-02-05'), y: 2647653 }, { x: new Date('2026-02-06'), y: 2594674 }, { x: new Date('2026-02-07'), y: 2706291 }, { x: new Date('2026-02-09'), y: 2740821 }, { x: new Date('2026-02-10'), y: 2743597 }, { x: new Date('2026-02-11'), y: 2748552 } ], beli: [ { x: new Date('2025-12-13'), y: 2396518 }, { x: new Date('2025-12-15'), y: 2401234 }, { x: new Date('2025-12-16'), y: 2403418 }, { x: new Date('2025-12-17'), y: 2426091 }, { x: new Date('2025-12-18'), y: 2425234 }, { x: new Date('2025-12-19'), y: 2424122 }, { x: new Date('2025-12-20'), y: 2430448 }, { x: new Date('2025-12-22'), y: 2452043 }, { x: new Date('2025-12-23'), y: 2514434 }, { x: new Date('2025-12-24'), y: 2534964 }, { x: new Date('2025-12-25'), y: 2514608 }, { x: new Date('2025-12-26'), y: 2539948 }, { x: new Date('2025-12-29'), y: 2531053 }, { x: new Date('2025-12-30'), y: 2442665 }, { x: new Date('2025-12-31'), y: 2436210 }, { x: new Date('2026-01-02'), y: 2436778 }, { x: new Date('2026-01-03'), y: 2427958 }, { x: new Date('2026-01-04'), y: 2427958 }, { x: new Date('2026-01-05'), y: 2465138 }, { x: new Date('2026-01-06'), y: 2493484 }, { x: new Date('2026-01-07'), y: 2524160 }, { x: new Date('2026-01-08'), y: 2501562 }, { x: new Date('2026-01-09'), y: 2516312 }, { x: new Date('2026-01-10'), y: 2551865 }, { x: new Date('2026-01-11'), y: 2593004 }, { x: new Date('2026-01-13'), y: 2594307 }, { x: new Date('2026-01-14'), y: 2605882 }, { x: new Date('2026-01-15'), y: 2608561 }, { x: new Date('2026-01-16'), y: 2603912 }, { x: new Date('2026-01-17'), y: 2606290 }, { x: new Date('2026-01-19'), y: 2651709 }, { x: new Date('2026-01-20'), y: 2648100 }, { x: new Date('2026-01-21'), y: 2721684 }, { x: new Date('2026-01-22'), y: 2717293 }, { x: new Date('2026-01-23'), y: 2800151 }, { x: new Date('2026-01-24'), y: 2801780 }, { x: new Date('2026-01-26'), y: 2833390 }, { x: new Date('2026-01-27'), y: 2823444 }, { x: new Date('2026-01-28'), y: 2892597 }, { x: new Date('2026-01-29'), y: 3040314 }, { x: new Date('2026-01-30'), y: 3040314 }, { x: new Date('2026-01-31'), y: 2749920 }, { x: new Date('2026-02-02'), y: 2675008 }, { x: new Date('2026-02-03'), y: 2686433 }, { x: new Date('2026-02-04'), y: 2814895 }, { x: new Date('2026-02-05'), y: 2742552 }, { x: new Date('2026-02-06'), y: 2688166 }, { x: new Date('2026-02-07'), y: 2804964 }, { x: new Date('2026-02-09'), y: 2839312 }, { x: new Date('2026-02-10'), y: 2837256 }, { x: new Date('2026-02-11'), y: 2842329 } ] }; 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');