PHP code example of mohsen-mhm / laravel-image-charts
1. Go to this page and download the library: Download mohsen-mhm/laravel-image-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/ */
mohsen-mhm / laravel-image-charts example snippets
return [
'base_url' => env('IMAGE_CHARTS_BASE_URL', 'https://image-charts.com/chart.js/2.8.0'),
'default_bg_color' => '#2B2B2B',
'default_dataset_bg_color' => '#FCBB3D',
'default_dataset_border_color' => '#FCBB3D',
'default_width' => '900',
'default_height' => '600',
'default_title_text' => 'mohsen.sbs',
'default_image_path' => storage_path('app/public/charts'),
];
use MohsenMhm\LaravelImageCharts\ImageChart;
$chartUrl = (new ImageChart())
->setData([10, 20, 30])
->setLabels(['January', 'February', 'March'])
->getUrl();
use MohsenMhm\LaravelImageCharts\Facades\ImageChartFacade as ImageChart;
$chartUrl = ImageChart::setData([10, 20, 30])
->setLabels(['January', 'February', 'March'])
->getUrl();
use MohsenMhm\LaravelImageCharts\ImageChart;
$fullImagePath = (new ImageChart())
->setData([10, 20, 30])
->setLabels(['January', 'February', 'March'])
->getImage();
use MohsenMhm\LaravelImageCharts\Facades\ImageChartFacade as ImageChart;
$fullImagePath = ImageChart::setData([10, 20, 30])
->setLabels(['January', 'February', 'March'])
->getImage();
use MohsenMhm\LaravelImageCharts\ImageChart;
$customPath = storage_path('app/public/custom_charts');
$fullImagePath = (new ImageChart())
->setData([10, 20, 30])
->setLabels(['January', 'February', 'March'])
->getImage($customPath);
use MohsenMhm\LaravelImageCharts\Facades\ImageChartFacade as ImageChart;
$customPath = storage_path('app/public/custom_charts');
$fullImagePath = ImageChart::setData([10, 20, 30])
->setLabels(['January', 'February', 'March'])
->getImage($customPath);
use MohsenMhm\LaravelImageCharts\ImageChart;
try {
$imageChart = (new ImageChart())
->setLabels(['January', 'February', 'March'])
->setData([10, 20, 30])
->setBackgroundColor('#FFFFFF')
->setDatasetBackgroundColor('#FF0000')
->setDatasetBorderColor('#0000FF')
->setWidth('800')
->setHeight('400')
->setTitleText('Monthly Data');
$chartUrl = $imageChart->getUrl();
$imagePath = $imageChart->getImage();
$binaryData = $imageChart->getBinary();
echo "Chart URL: $chartUrl\n";
echo "Image saved at: $imagePath\n";
echo "image in binary format: $binaryData\n";
} catch (InvalidArgumentException $e) {
echo 'Error: ' . $e->getMessage();
}
bash
php artisan vendor:publish --provider="MohsenMhm\LaravelImageCharts\Providers\ImageChartsServiceProvider" --tag="config"