where('created_at', '>=', now()->subDays(7)) ->groupBy('date') ->orderBy('date') ->get(); $labels = $data->pluck('date')->map(function ($date) { return Jalalian::fromCarbon(\Carbon\Carbon::parse($date))->format('l d'); })->toArray(); $deposits = $data->pluck('deposits')->map(fn ($v) => (float) $v)->toArray(); $withdrawals = $data->pluck('withdrawals')->map(fn ($v) => (float) $v)->toArray(); return [ 'datasets' => [ [ 'label' => 'واریزی‌ها', 'data' => $deposits, 'borderColor' => '#10b981', 'backgroundColor' => 'rgba(16, 185, 129, 0.15)', 'fill' => true, 'tension' => 0.4, 'pointRadius' => 3, 'pointHoverRadius' => 5, 'pointBackgroundColor' => '#10b981', ], [ 'label' => 'برداشت‌ها', 'data' => $withdrawals, 'borderColor' => '#f59e0b', 'backgroundColor' => 'rgba(245, 158, 11, 0.15)', 'fill' => true, 'tension' => 0.4, 'pointRadius' => 3, 'pointHoverRadius' => 5, 'pointBackgroundColor' => '#f59e0b', ], ], 'labels' => $labels, ]; } protected function getType(): string { return 'line'; } protected function getOptions(): array { return [ 'plugins' => [ 'legend' => [ 'position' => 'top', 'align' => 'end', 'labels' => [ 'font' => [ 'family' => 'Vazirmatn', 'size' => 12, ], 'usePointStyle' => true, 'boxWidth' => 8, ], ], 'tooltip' => [ 'callbacks' => [ 'label' => 'function(context) { var v = context.parsed.y; if (v === null || v === undefined) return ""; return context.dataset.label + ": " + v.toLocaleString("fa-IR") + " ریال"; }', ], ], ], 'scales' => [ 'y' => [ 'beginAtZero' => true, 'ticks' => [ 'callback' => 'function(value) { return value.toLocaleString("fa-IR"); }', 'font' => ['family' => 'Vazirmatn', 'size' => 11], ], 'grid' => [ 'color' => 'rgba(0, 0, 0, 0.05)', ], ], 'x' => [ 'ticks' => [ 'maxRotation' => 0, 'font' => ['family' => 'Vazirmatn', 'size' => 11], ], 'grid' => [ 'display' => false, ], ], ], 'maintainAspectRatio' => false, ]; } }