kevinkhill / lavacharts

Lavacharts is a graphing / charting library for PHP 5.4+ that wraps Google's Javascript Chart API.
http://lavacharts.com
Other
619 stars 142 forks source link

is this chart package still compatible with Laravel version 10? #348

Closed jarwonozt closed 1 month ago

jarwonozt commented 9 months ago

What Version?

Run composer show khill/lavacharts if you don't know

Issue

Please describe the issue.

Controller Code (chart creation code)

// paste over this

View Code

// paste over this
focaicedoc commented 4 months 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.

focaicedoc commented 4 months ago

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>
Screen Shot 2024-05-07 at 8 32 27 PM

Best regards!

jarwonozt commented 4 months 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.

Haha, thank you for answering. It seems like this package hasn't been updated yet, so I'm using a different charting technology

davidvandertuijn commented 3 months ago

Keep this in Laravel 11 in app/config.php:

'aliases' => Facade::defaultAliases()->merge([
    'Lavacharts' => Khill\Lavacharts\Laravel\LavachartsFacade::class,
])->toArray(),