diff --git a/src/DatesFunctions.php b/src/DatesFunctions.php index 457c246..b656675 100644 --- a/src/DatesFunctions.php +++ b/src/DatesFunctions.php @@ -206,7 +206,10 @@ protected function getLabelsData(): array $result = []; $labelColumn = explode('.', $this->labelColumn)[1]; - $missingDataLabels = DB::table($this->table)->get()->pluck($labelColumn)->toArray(); + + $missingDataLabels = empty($this->missingDataLabels) + ? DB::table($this->table)->get()->pluck($labelColumn)->toArray() + : $this->missingDataLabels; foreach ($missingDataLabels as $label) { $result[$label] = $this->missingDataValue; diff --git a/src/LaravelMetrics.php b/src/LaravelMetrics.php index 3439b6c..906cc8e 100644 --- a/src/LaravelMetrics.php +++ b/src/LaravelMetrics.php @@ -53,6 +53,8 @@ class LaravelMetrics protected int $missingDataValue = 0; + protected array $missingDataLabels = []; + protected string $groupBy; public function __construct(protected Builder|QueryBuilder $builder) @@ -441,10 +443,11 @@ public function labelColumn(string $column): self return $this; } - public function fillMissingData(int $missingDataValue = 0): self + public function fillMissingData(int $missingDataValue = 0, array $missingDataLabels = []): self { $this->fillMissingData = true; $this->missingDataValue = $missingDataValue; + $this->missingDataLabels = $missingDataLabels; return $this; }