Closed jarwonozt closed 1 month ago
It's a shame to see this project abandoned. You can always fight to get it to work in Laravel 10 or 11... however, it's not worth it.
The official documentation has some errors..., however here you have an example under Laravel 11 using Dashboard wrapping
namespace App\View\Components\Reports;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use Illuminate\Database\Query\JoinClause;
use Khill\Lavacharts\Lavacharts;
use Illuminate\Support\Facades\DB;
class DebitByCategoryReport extends Component
{
public function __construct()
{
$data_table = \Lava::DataTable();
$data_table->addStringColumn('Categoría')->addNumberColumn('Valor')->addStringColumn('Usuario');
$debits_by_category = DB::table('debits')
->select(
DB::raw("sum(amount) as debits_by_category"),
DB::raw("debit_categories.name as category"),
'users.name as uname'
)
->join('debit_categories', function (JoinClause $join){
$join->on('debits.category_id', '=', 'debit_categories.id')
->where('debit_categories.reportable', '=', 1);
})
->join('users', 'debits.user_id', '=', 'users.id')
->groupBy(['category', 'uname'])->get();
foreach ($debits_by_category as $dbc) {
$data_table->addRow([$dbc->category, $dbc->debits_by_category, $dbc->uname]);
}
$pieChart = \Lava::PieChart('Debits', $data_table, [
'title' => 'Egresos por Categoría',
'is3D' => false,
'height' => 350,
'chartArea' => [
'width' => '75%',
'height' => '75%',
],
'legend' => [
'position' => 'bottom',
'alignment' => 'center',
'textStyle' => [
'fontSize' => 8
],
'maxLines' => 1
],
'pieSliceText' => 'value'
]);
$categoryFilter = \Lava::CategoryFilter(2, [
'ui' => [
'labelStacking' => 'horizontal',
'label' => 'Usuario',
'sortValues' => false,
'allowTyping' => false,
'allowMultiple' => false,
'allowNone' => false
]
]);
$control = \Lava::ControlWrapper($categoryFilter, 'debit-by-category-report-control-div');
$chart = \Lava::ChartWrapper($pieChart, 'debit-by-category-report-chart-div');
\Lava::Dashboard('DebitsByCategory', $data_table)->bind($control, $chart);
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.reports.debit-by-category-report');
}
}
And the view
<div id="debit-by-category-report-dashboard-div">
<div id="debit-by-category-report-chart-div"></div>
<div id="debit-by-category-report-control-div"></div>
@dashboard('DebitsByCategory', 'debit-by-category-report-dashboard-div')
</div>
Best regards!
It's a shame to see this project abandoned. You can always fight to get it to work in Laravel 10 or 11... however, it's not worth it.
Haha, thank you for answering. It seems like this package hasn't been updated yet, so I'm using a different charting technology
Keep this in Laravel 11 in app/config.php:
'aliases' => Facade::defaultAliases()->merge([
'Lavacharts' => Khill\Lavacharts\Laravel\LavachartsFacade::class,
])->toArray(),
What Version?
Issue
Controller Code (chart creation code)
View Code