1. Go to this page and download the library: Download nabcellent/chartisan 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/ */
nabcellent / chartisan example snippets
declare(strict_types = 1);
namespace App\Charts;
use Illuminate\Http\Request;
use Nabcellent\Chartisan\BaseChart;
use Nabcellent\Chartisan\Chartisan\Chartisan;
class SampleChart extends BaseChart
{
/**
* Handles the HTTP request for the given chart.
* It must always return an instance of Chartisan
* and never a string or an array.
*/
public function handler(Request $request): Chartisan
{
return Chartisan::build()
->labels(['First', 'Second', 'Third'])
->dataset('Sample', [1, 2, 3])
->dataset('Sample 2', [3, 2, 1]);
}
}
namespace App\Providers;
use App\Charts\SampleChart;
use Nabcellent\Chartisan\Registrar as Chartisan;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
// ...
/**
* Bootstrap any application services.
*/
public function boot(Chartisan $charts)
{
$charts->register([
SampleChart::class
]);
}
}
declare(strict_types = 1);
namespace App\Charts;
use Illuminate\Http\Request;
use Nabcellent\Chartisan\BaseChart;
use Nabcellent\Chartisan\Chartisan\Chartisan;
class SampleChart extends BaseChart
{
/**
* Determines the chart name to be used on the
* route. If null, the name will be a snake_case
* version of the class name.
*/
public ?string $name = 'custom_chart_name';
/**
* Determines the name suffix of the chart route.
* This will also be used to get the chart URL
* from the blade directive. If null, the chart
* name will be used.
*/
public ?string $routeName = 'chart_route_name';
/**
* Determines the prefix that will be used by the chart
* endpoint.
*/
public ?string $prefix = 'some_prefix';
/**
* Determines the middlewares that will be applied
* to the chart endpoint.
*/
public ?array $middlewares = ['auth'];
/**
* Handles the HTTP request for the given chart.
* It must always return an instance of Chartisan
* and never a string or an array.
*/
public function handler(Request $request): Chartisan
{
return Chartisan::build()
->labels(['First', 'Second', 'Third'])
->dataset('Sample', [1, 2, 3])
->dataset('Sample 2', [3, 2, 1]);
}
}
php artisan vendor:publish --tag=chartisan
php artisan make:chart SampleChart
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.