PHP code example of ridwan / laravel-pdf-charts
1. Go to this page and download the library: Download ridwan/laravel-pdf-charts 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/ */
ridwan / laravel-pdf-charts example snippets
use Ridwan\LaravelPdfCharts\Facades\Chart;
$image = Chart::make([
'type' => 'bar',
'data' => [
'labels' => ['Jan', 'Feb', 'Mar'],
'datasets' => [
[
'label' => 'Sales',
'data' => [120, 180, 150],
],
],
],
])->render();
Chart::make([
'type' => 'bar',
'data' => [
'labels' => ['Jan', 'Feb', 'Mar'],
'datasets' => [
[
'label' => 'Sales',
'data' => [120, 180, 150],
],
],
],
])->render();
Chart::make([
'type' => 'line',
'data' => [
'labels' => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
'datasets' => [
[
'label' => 'Visitors',
'data' => [12, 19, 8, 15, 22],
'fill' => false,
],
],
],
])->render();
Chart::make([
'type' => 'pie',
'data' => [
'labels' => ['Red', 'Blue', 'Yellow'],
'datasets' => [
[
'data' => [300, 50, 100],
],
],
],
])->render();
Chart::make([
'type' => 'doughnut',
'data' => [
'labels' => ['Desktop', 'Mobile', 'Tablet'],
'datasets' => [
[
'data' => [55, 35, 10],
],
],
],
])->render();
Chart::make([
'type' => 'radar',
'data' => [
'labels' => [
'Speed',
'Power',
'Range',
'Durability',
'Accuracy',
],
'datasets' => [
[
'label' => 'Player A',
'data' => [65, 59, 90, 81, 56],
],
],
],
])->render();
Chart::make([
'type' => 'polarArea',
'data' => [
'labels' => [
'Red',
'Green',
'Yellow',
'Grey',
'Blue',
],
'datasets' => [
[
'data' => [11, 16, 7, 3, 14],
],
],
],
])->render();
Chart::make([
'type' => 'scatter',
'data' => [
'datasets' => [
[
'label' => 'Scatter Dataset',
'data' => [
['x' => -10, 'y' => 0],
['x' => 0, 'y' => 10],
['x' => 10, 'y' => 5],
],
],
],
],
])->render();
Chart::make([
'type' => 'bubble',
'data' => [
'datasets' => [
[
'label' => 'Bubbles',
'data' => [
['x' => 20, 'y' => 30, 'r' => 15],
['x' => 40, 'y' => 10, 'r' => 10],
['x' => 30, 'y' => 20, 'r' => 25],
],
],
],
],
])->render();
$image = Chart::make($config)
->width(800)
->height(400)
->format('png')
->backgroundColor('white')
->devicePixelRatio(2)
->version('4')
->render();
$chart = Chart::make($config)
->width(1200)
->height(600)
->format('png')
->render();
$dataUri = Chart::make($config)->toBase64();
$raw = Chart::make($config)
->toBase64(dataUri: false);
$path = Chart::make($config)
->save(storage_path('app/charts/sales.png'));
$path = Chart::make($config)
->format('pdf')
->save(storage_path('app/charts/sales.pdf'));
bash
php artisan vendor:publish --tag=pdf-charts-config