PHP code example of wangta69 / laravel-chart
1. Go to this page and download the library: Download wangta69/laravel-chart 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/ */
wangta69 / laravel-chart example snippets
use Pondol\Charts\Facades\Chartjs;
..........
$data = ['all'=>['jan'=>34, 'feb'=>56...], 'unique'=>[...]]
..........
$chart = Chartjs::
type('line')
->element('dailyChart')
->labels(array_keys($data['all']))
->datasets(function($dataset) use($data) {
$dataset->setLabel("# all");
$dataset->setData(array_values($data['all']));
$dataset->setBorderWidth(1);
})
->datasets(function($dataset) use($data) {
$dataset->setLabel("# unique");
$dataset->setData(array_values($data['unique']));
$dataset->setBorderWidth(1);
})
->options(function($option) {
$option->setTitle('Daily visitor');
})
->build();
$chartData = array_column($data , 'count');
$chart = Chartjs::refresh()
->type('bar')
->element('countryChart')
->datasets(function($dataset) use($data) {
$dataset->setData(array_column($data , 'count'));
$dataset->setdefaultColor();
})
->labels(array_column($data , 'country'));
$chart = $chart->options(function($option) {
$option->legend['display'] = false;
$option->setTitle('Nationals');
})
->build();