Hoping for some help troubleshooting and issue after Laravel 10.x to 11.x upgrade.
I've been using icehouse-ventures/laravel-chartjs (https://github.com/icehouse-ventures/laravel-chartjs) for over a year, displaying various charts in my app. A couple days ago, I upgraded Laravel from 10.x to 11.x and, in the process, upgraded laravel-chartjs from 1.1 to 4.1 as well. After these upgrades, none of my charts are working anymore.
I'm using the Livewire implementation. To keep troubleshooting super simple, I basically tried a brand new chart with a nearly exact copy/paste from the readme example.
ChartReadRatio.php
<?php
namespace App\Livewire;
use Livewire\Attributes\Computed;
use Livewire\Component;
use IcehouseVentures\LaravelChartjs\Facades\Chartjs;
class ChartReadRatio extends Component
{
public $user;
public $datasets;
public $stat_readInCol;
public $stat_numBookInCol;
#[Computed]
public function chart()
{
return Chartjs::build()
->name('readRatioChart')
->livewire()
->model('datasets')
->type("line");
}
public function render()
{
$this->getData();
return view('livewire.chart-read-ratio');
}
public function getData()
{
$data = [1, 2, 3]; // your data here
$labels = ['a', 'b', 'c']; // your labels here
$this->datasets = [
'datasets' => [
[
"label" => "User Registrations",
"backgroundColor" => "rgba(38, 185, 154, 0.31)",
"borderColor" => "rgba(38, 185, 154, 0.7)",
"data" => $data
]
],
'labels' => $labels
];
}
}
chart-read-ratio.blade.php
<div class="col-span-2">
<div class="chart-container">
<x-chartjs-component :chart="$chart" />
</div>
</div>
When I visit the page, I'm getting the following error: "Undefined variable $chart"
With this line highlighted:
<x-chartjs-component :chart="$chart" />
Also, just as a quick sanity check to make sure everything was installed correctly, I also basically copy/pasted the readme example for a regular (non livewire) line chart and it worked fine - I was able to view the chart. All I had to change from the example is I removed "compact()" from the view return.
I also opened an issue in the Github repo, but it's small so I don't know how likely I am to get help there.
I know there may not be a huge number of people that have experience with this library but I'm hoping someone will see this and have a good idea on where to start or how to troubleshoot.
Please or to participate in this conversation.