asantibanez / livewire-charts

Neat Livewire Charts for your Laravel projects
MIT License
788 stars 116 forks source link

Argument 1 passed to Asantibanez\LivewireCharts\Charts\LivewireColumnChart::mount() must be an instance of Asantibanez\LivewireCharts\Models\ColumnChartModel, null given, #37

Closed ChristianAdrian closed 2 years ago

ChristianAdrian commented 3 years ago

`$expenses = Admin::whereIn('team_id', ['5','6'])->get();

    $columnChartModel = $expenses->groupBy('team_id')
    ->reduce(function ($columnChartModel, $data) {
        $type = $data->first()->team_id;
        $value = $data->sum('id');

        return $columnChartModel->addColumn($type, $value, $this->colors[$type]);
    },LivewireCharts::columnChartModel()
        ->setTitle('Expenses by Typssse')
        ->setAnimated($this->firstRun)
        ->withOnColumnClickEventName('onColumnClick')
        ->setLegendVisibility(false)
        ->setDataLabelsEnabled($this->showDataLabels)
        ->setOpacity(0.25)
        ->setColors(['#b01a1b', '#d41b2c'])
        ->setColumnWidth(90)

    );

` image

been trying to integrate charts in my project and used the sample but i keep gettin gthis error I check the value of columnChartModel and it has value

atmonshi commented 3 years ago

I am having the same issue, how you fixed this??

JuanDeLeon commented 3 years ago

Make sure you are passing the model as an argument to the view helper in render() function, do not declare it as a public property.

return view('livewire.your-view', [
   'lineChartModel' => $lineChartModel
]);
goncoolio commented 2 years ago

`public $date_debut= '2022-03-05'; public $date_fin = '2022-03-11'; public $search;

public $firstRun = true;

// public function mount()
// {
//     $this->date_debut = '2022-03-05';
//     $this->date_fin = now() ;
// }

public function render()
{

    $date_debut = Carbon::parse($this->date_debut)->format('Y-m-d');
    $date_fin = Carbon::parse($this->date_fin)->format('Y-m-d');

    // $total = $programme->count();
    // $archiver = $programme->where('programme_archiver', 'Archiver')->count();

    $programme = Programme::whereBetween('created_at',  [$date_debut, $date_fin])->get();
    $pieChartModel = $programme->groupBy('programme_archiver')
        ->reduce(
            function (PieChartModel $pieChartModel, $data) {
                $archiverPie = $data->first()->programme_archiver;
                $value = $data->count();
                return $pieChartModel->addSlice($archiverPie, $value, ['#f6ad55','#fc8181']);
            },
            (new PieChartModel() )
                ->setTitle('Expenses by Statut')
                ->setAnimated($this->firstRun)
                // ->withOnSliceClickEvent('onSliceClick')

        );

        // dd($pieChartModel);

    return view('livewire.reporting.r-programme', [
        'pieChartModel' => $pieChartModel,
        'total' => $total,
        'archiver' => $archiver,
        'non_archiver' => $total - $archiver,

    ]);`

this my code i have same problem Can you help me ?