PHP code example of jccoca / filament-chart-palette
1. Go to this page and download the library: Download jccoca/filament-chart-palette library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jccoca / filament-chart-palette example snippets
namespace App\Filament\Widgets;
use Filament\Widgets\ChartWidget;
use JCCoca\FilamentChartPalette\Traits\HasChartPalette;
class UsersOverviewChart extends ChartWidget
{
use HasChartPalette;
protected static ?string $heading = 'Users Overview';
protected function getData(): array
{
// Get a ready-to-use RGBA color palette optimized for 'pie' charts (shade step 400)
$palette = $this->getChartPalette('pie', 400);
$palette = $this->getChartPalette($this->getType());
return [
'datasets' => [
[
'label' => 'Users',
'data' => [300, 50, 100, 40, 120],
'backgroundColor' => $palette,
],
],
'labels' => ['Active', 'Pending', 'Banned', 'Inactive', 'Archived'],
];
}
protected function getType(): string
{
return 'pie';
}
}
namespace App\Filament\Widgets;
use Filament\Widgets\ChartWidget;
use JCCoca\FilamentChartPalette\Traits\HasChartPalette;
class UsersOverviewChart extends ChartWidget
{
use HasChartPalette;
protected static ?string $heading = 'Users Overview';
protected function getData(): array
{
// Automatically fetches the palette optimized for current chart type ($this->getType())
$palette = $this->getChartPalette($this->getType());
return [
'datasets' => [
[
'label' => 'Users',
'data' => [300, 50, 100, 40, 120],
'backgroundColor' => $palette,
],
],
'labels' => ['Active', 'Pending', 'Banned', 'Inactive', 'Archived'],
];
}
protected function getType(): string
{
return 'pie';
}
}