ConsoleTVs / Charts

[Deprecated] Charts for Laravel
MIT License
72 stars 33 forks source link

[QUESTION] Chartjs legend position #8

Open ThomasLoSG opened 1 year ago

ThomasLoSG commented 1 year ago

Is there any way to change the position of legend?

SantanuDatta commented 1 year ago

Is there any way to change the position of legend?

hello, I used it this way $chart->options([ 'legend' => [ 'position' => 'bottom', ] ]);

JasonJensenDev commented 1 year ago

Is there any way to change the position of legend?

hello, I used it this way $chart->options([ 'legend' => [ 'position' => 'bottom', ] ]);

Thanks for posting this question and answer! I tried doing exactly what you did, @SantanuDatta, and my legend position is still top. Any other advice to get my legend to the bottom of the chart?

SantanuDatta commented 1 year ago

First I created a chart

php artisan make:chart {Name} {Library?}

then inside that chart function, I used it like this

public function __construct()
{
parent::__construct();
$this->options([
'responsive' => true,
'legend' => [
'position' => 'bottom',
],
'scales' => [
'yAxes' => [
[
'ticks' => [
'beginAtZero' => true,
],
'gridLines' => [
'display' => true,
'color' => 'rgba(0, 0, 0, 0.1)',
],
],
],
'xAxes' => [
[
'gridLines' => [
'display' => true,
],
],
],
],
]);
}

and the main work I did inside the controller and it worked for me