From 3d6f210fe939d9038738ff425270d1689b86b5ba Mon Sep 17 00:00:00 2001 From: Henning Zimmermann Date: Mon, 5 Feb 2024 09:04:14 +0100 Subject: [PATCH] - Configuration for the visibility of the legend --- src/LarapexChart.php | 18 ++++++++++++++++++ stubs/resources/views/chart/script.blade.php | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/LarapexChart.php b/src/LarapexChart.php index b3b8455..fa6dc36 100644 --- a/src/LarapexChart.php +++ b/src/LarapexChart.php @@ -34,6 +34,7 @@ class LarapexChart protected string $grid; protected string $markers; protected bool $stacked = false; + protected bool $showLegend = true; protected string $stroke = ''; protected string $toolbar; protected string $zoom; @@ -278,6 +279,12 @@ public function setStacked(bool $stacked = true): LarapexChart return $this; } + public function setShowLegend(bool $showLegend = true): self + { + $this->showLegend = $showLegend; + return $this; + } + /* |-------------------------------------------------------------------------- | Getters @@ -417,6 +424,11 @@ public function stacked(): bool return $this->stacked; } + public function showLegend(): string + { + return $this->showLegend ? 'true' : 'false'; + } + /* |-------------------------------------------------------------------------- | JSON Options Builder @@ -458,6 +470,9 @@ public function toJson(): \Illuminate\Http\JsonResponse ], 'grid' => json_decode($this->grid()), 'markers' => json_decode($this->markers()), + 'legend' => [ + 'show' => $this->showLegend() + ], ]; if($this->labels()) { @@ -512,6 +527,9 @@ public function toVue() :array ], 'grid' => json_decode($this->grid()), 'markers' => json_decode($this->markers()), + 'legend' => [ + 'show' => $this->showLegend() + ] ]; if($this->labels()) { diff --git a/stubs/resources/views/chart/script.blade.php b/stubs/resources/views/chart/script.blade.php index 17ba356..3e101ac 100644 --- a/stubs/resources/views/chart/script.blade.php +++ b/stubs/resources/views/chart/script.blade.php @@ -38,6 +38,9 @@ @if($chart->stroke()) stroke: {!! $chart->stroke() !!}, @endif + legend: { + show: {!! $chart->showLegend() !!} + } } var chart = new ApexCharts(document.querySelector("#{!! $chart->id() !!}"), options);