forked from fxcosta/laravel-chartjs
-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Laravel charts has been working great for me for the last year in Laravel 10 and laravel-chartjs 1.1. I recently upgraded both Laravel and laravel-chartjs to 11 and 4.1 respectively at the same time and have run into an issue with all of my charts.
I'm using the Livewire implementation. To keep things 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" />
I'm, admittedly, not a wiz with Laravel so don't assume I know anything. Could be a super simple correction.
Metadata
Metadata
Assignees
Labels
No labels