Charts icon indicating copy to clipboard operation
Charts copied to clipboard

[QUESTION] Chartjs legend position

Open ThomasLoSG opened this issue 2 years ago • 3 comments

Is there any way to change the position of legend?

ThomasLoSG avatar Oct 04 '22 15:10 ThomasLoSG

Is there any way to change the position of legend?

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

SantanuDatta avatar Mar 14 '23 11:03 SantanuDatta

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?

JasonJensenDev avatar Apr 27 '23 00:04 JasonJensenDev

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

SantanuDatta avatar Apr 27 '23 09:04 SantanuDatta