const allData = { jual: [ { x: new Date('2025-12-13'), y: 2469965 }, { x: new Date('2025-12-15'), y: 2482599 }, { x: new Date('2025-12-16'), y: 2479232 }, { x: new Date('2025-12-17'), y: 2465180 }, { x: new Date('2025-12-18'), y: 2480810 }, { x: new Date('2025-12-19'), y: 2492211 }, { x: new Date('2025-12-20'), y: 2476005 }, { x: new Date('2025-12-22'), y: 2488670 }, { x: new Date('2025-12-23'), y: 2556815 }, { x: new Date('2025-12-24'), y: 2583403 }, { x: new Date('2025-12-25'), y: 2543961 }, { x: new Date('2025-12-26'), y: 2560231 }, { x: new Date('2025-12-29'), y: 2558043 }, { x: new Date('2025-12-30'), y: 2475524 }, { x: new Date('2025-12-31'), y: 2488528 }, { x: new Date('2026-01-02'), y: 2486634 }, { x: new Date('2026-01-03'), y: 2475026 }, { x: new Date('2026-01-04'), y: 2475026 }, { x: new Date('2026-01-05'), y: 2512129 }, { x: new Date('2026-01-06'), y: 2512129 }, { x: new Date('2026-01-07'), y: 2528589 }, { x: new Date('2026-01-08'), y: 2532894 }, { x: new Date('2026-01-09'), y: 2517686 }, { x: new Date('2026-01-10'), y: 2523079 }, { x: new Date('2026-01-11'), y: 2407594 }, { x: new Date('2026-01-13'), y: 2590784 }, { x: new Date('2026-01-14'), y: 2595386 }, { x: new Date('2026-01-15'), y: 2614979 }, { x: new Date('2026-01-16'), y: 2602334 }, { x: new Date('2026-01-17'), y: 2588954 }, { x: new Date('2026-01-19'), y: 2602334 }, { x: new Date('2026-01-20'), y: 2644640 }, { x: new Date('2026-01-21'), y: 2659988 }, { x: new Date('2026-01-22'), y: 2701484 }, { x: new Date('2026-01-23'), y: 2739384 }, { x: new Date('2026-01-24'), y: 2811292 }, { x: new Date('2026-01-26'), y: 2812730 }, { x: new Date('2026-01-27'), y: 2854000 }, { x: new Date('2026-01-28'), y: 2900237 }, { x: new Date('2026-01-29'), y: 3026549 }, { x: new Date('2026-01-30'), y: 2952692 }, { x: new Date('2026-01-31'), y: 2746832 }, { x: new Date('2026-02-02'), y: 2680802 }, { x: new Date('2026-02-03'), y: 2625360 }, { x: new Date('2026-02-04'), y: 2731164 }, { x: new Date('2026-02-05'), y: 2704731 }, { x: new Date('2026-02-06'), y: 2610297 }, { x: new Date('2026-02-07'), y: 2757161 }, { x: new Date('2026-02-09'), y: 2790820 }, { x: new Date('2026-02-10'), y: 2813018 }, { x: new Date('2026-02-11'), y: 2797756 } ], beli: [ { x: new Date('2025-12-13'), y: 2583673 }, { x: new Date('2025-12-15'), y: 2571039 }, { x: new Date('2025-12-16'), y: 2567552 }, { x: new Date('2025-12-17'), y: 2553000 }, { x: new Date('2025-12-18'), y: 2569186 }, { x: new Date('2025-12-19'), y: 2580993 }, { x: new Date('2025-12-20'), y: 2589991 }, { x: new Date('2025-12-22'), y: 2577326 }, { x: new Date('2025-12-23'), y: 2671320 }, { x: new Date('2025-12-24'), y: 2675433 }, { x: new Date('2025-12-25'), y: 2735384 }, { x: new Date('2025-12-26'), y: 2733459 }, { x: new Date('2025-12-29'), y: 2702715 }, { x: new Date('2025-12-30'), y: 2624970 }, { x: new Date('2025-12-31'), y: 2655716 }, { x: new Date('2026-01-02'), y: 2627268 }, { x: new Date('2026-01-03'), y: 2641308 }, { x: new Date('2026-01-04'), y: 2641308 }, { x: new Date('2026-01-05'), y: 2654205 }, { x: new Date('2026-01-06'), y: 2663504 }, { x: new Date('2026-01-07'), y: 2698116 }, { x: new Date('2026-01-08'), y: 2676144 }, { x: new Date('2026-01-09'), y: 2660076 }, { x: new Date('2026-01-10'), y: 2692589 }, { x: new Date('2026-01-11'), y: 2779678 }, { x: new Date('2026-01-13'), y: 2737308 }, { x: new Date('2026-01-14'), y: 2742170 }, { x: new Date('2026-01-15'), y: 2763423 }, { x: new Date('2026-01-16'), y: 2749510 }, { x: new Date('2026-01-17'), y: 2762890 }, { x: new Date('2026-01-19'), y: 2749510 }, { x: new Date('2026-01-20'), y: 2794210 }, { x: new Date('2026-01-21'), y: 2810426 }, { x: new Date('2026-01-22'), y: 2868588 }, { x: new Date('2026-01-23'), y: 2896630 }, { x: new Date('2026-01-24'), y: 2914355 }, { x: new Date('2026-01-26'), y: 2915852 }, { x: new Date('2026-01-27'), y: 2958628 }, { x: new Date('2026-01-28'), y: 3001753 }, { x: new Date('2026-01-29'), y: 3205336 }, { x: new Date('2026-01-30'), y: 3165186 }, { x: new Date('2026-01-31'), y: 3035191 }, { x: new Date('2026-02-02'), y: 3012937 }, { x: new Date('2026-02-03'), y: 2853411 }, { x: new Date('2026-02-04'), y: 3030494 }, { x: new Date('2026-02-05'), y: 3057247 }, { x: new Date('2026-02-06'), y: 2969972 }, { x: new Date('2026-02-07'), y: 2916558 }, { x: new Date('2026-02-09'), y: 2920761 }, { x: new Date('2026-02-10'), y: 2956487 }, { x: new Date('2026-02-11'), y: 2945983 } ] }; 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');