Skip to content

Commit

Permalink
- configuration of the minimum, maximum, tick amount of the y-axis
Browse files Browse the repository at this point in the history
  • Loading branch information
marineusde committed Jul 12, 2023
1 parent 21dc8bf commit 444deee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/LarapexChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class LarapexChart
protected string $zoom;
protected string $dataLabels;
protected string $sparkline;
protected bool $yAxisShow = false;
protected ?int $yAxisMin = null;
protected ?int $yAxisMax = null;
protected ?int $yAxisTickAmount = null;
private string $chartLetters = 'abcdefghijklmnopqrstuvwxyz';

/*
Expand Down Expand Up @@ -196,6 +200,16 @@ public function setXAxis(array $categories) :LarapexChart
return $this;
}

public function setYAxis(int $min, int $max, ?int $tickAmount = null, bool $show = true) :self
{
$this->yAxisMin = $min;
$this->yAxisMax = $max;
$this->yAxisTickAmount = $tickAmount ?? $max;
$this->yAxisShow = $show;

return $this;
}

public function setGrid($color = '#e5e5e5', $opacity = 0.1) :LarapexChart
{
$this->grid = json_encode([
Expand Down Expand Up @@ -366,6 +380,26 @@ public function xAxis(): string
return $this->xAxis;
}

public function yAxisMin(): ?int
{
return $this->yAxisMin;
}

public function yAxisMax(): ?int
{
return $this->yAxisMax;
}

public function yAxisTickAmount(): ?int
{
return $this->yAxisTickAmount;
}

public function yAxisShow(): bool
{
return $this->yAxisShow;
}

public function grid(): bool|string
{
return $this->grid;
Expand Down
12 changes: 12 additions & 0 deletions stubs/resources/views/chart/script.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
xaxis: {
categories: {!! $chart->xAxis() !!}
},
@if ($chart->yAxisMin() !== null && $chart->yAxisMax() !== null && $chart->yAxisTickAmount() !== null)
yaxis: {
@if ($chart->yAxisShow())
show: true,
@else
show: false,
@endif
min: {!! $chart->yAxisMin() !!},
max: {!! $chart->yAxisMax() !!},
tickAmount: {!! $chart->yAxisTickAmount() !!},
},
@endif
grid: {!! $chart->grid() !!},
markers: {!! $chart->markers() !!},
@if($chart->stroke())
Expand Down

0 comments on commit 444deee

Please sign in to comment.