Livewire Charts demo
Sample application on how to use asantibanez/livewire-charts
. Enjoy!
Installation
- Clone repository
- Install dependencies
- Run migrations and seed data with provided
ExpenseFactory
- Profit!
💪
Category: PHP / Miscellaneous |
Watchers: 2 |
Star: 31 |
Fork: 2 |
Last update: Oct 8, 2021 |
Sample application on how to use asantibanez/livewire-charts
. Enjoy!
ExpenseFactory
I made the mention of the package in the README a link, just to make it a little easier to navigate.
How can I set random color if there is any dynamic many data to be loaded which can't be predicted.
Is there a way to refresh chart after user change a value?
In this case i have three buttons that set different format for created_at field. I tried different solutions, but it doesn't seem to refresh the chart view.
Any tip? Please.
<?php
namespace App\Http\Livewire\Dashboard\Statistics\Charts\Pie;
use App\Models\LandingPageStatistics\VisitorsStatistic;
use Asantibanez\LivewireCharts\Facades\LivewireCharts;
use Asantibanez\LivewireCharts\Models\ColumnChartModel;
use Carbon\Carbon;
use Livewire\Component;
class VisitorsStatisticsPieCharts extends Component
{
public $page;
public $showDataLabels = true;
public $firstRun = true;
public $grouped ='d/m';
public $colors = [
];
public $newGroupBy;
protected $listeners = [
'refreshChart' => 'render',
];
public function setGroupBy($value){
$this->newGroupBy = $value;
dd($this->newGroupBy); // Here I see Input has submitted
$this->emit('refreshChart');
}
public function render()
{
$visits = VisitorsStatistic::where('page_id', $this->page->id)->orderBy('created_at')->get();
$columnChartModel = $visits->groupBy(function($date){
// NEED SOMTHING THAT SET NEW FORMAT
// if(isset($this->newGroupBy)){
// $this->grouped = $this->newGroupBy;
// }else{
// $this->grouped;
// }
return Carbon::parse($date->created_at)->format($this->grouped);
})->reduce(
function($columnChartModel, $data){
$visit = Carbon::parse($data->first()->created_at)->format('D d/m/y');
$value = $data->count();
return $columnChartModel->addColumn($visit, $value, $this->colors);
}, LivewireCharts::columnChartModel()
->setTitle(__('contents.visitors_statistics'))
->setAnimated($this->firstRun)
->setLegendVisibility(false)
->setDataLabelsEnabled($this->showDataLabels)
->setColors(['#0984e3'])
->setColumnWidth(20)
);
return view('livewire.dashboard.statistics.charts.pie.visitors-statistics-pie-charts',[
'columnChartModel' => $columnChartModel,
]);
}
}
}
Do you have a workaround for an Echarts solution
The graph is empty, you can only see the grid.