[Chartjs]-I can't change the legend position in Laravel Charts & ChartJS

1👍

I had the same problem – I could not pass some configurations using the "options"-method.

I solved it adding my own method to the UserChart class

namespace App\Charts;

use ConsoleTVs\Charts\Classes\ChartJs\Chart;

class UserChart extends Chart
{
    /**
     * Initializes the chart.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    public function legendPosition(string $position)
    {
        return $this->options([
            'legend' => [
                'position' => $position,
            ],
        ]);
    }
}

0👍

It only works in this order: $chart->options(…)->dataset()

dataset returns the data set which has different options and is on dataset level. ->labels() returns a BaseChart and there the option value works on chart level. If the chain is ->dataset()->options() it doesn’t work since the dataset doesn’t have a configurable legend.

Leave a comment