This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Home
Maarten Paauw edited this page Jan 17, 2022
·
1 revision
This package will help you generate CSS only charts based on the Charts.css library.
You can install the package via composer:
composer require maartenpaauw/laravel-charts-css
Here's how you can create a chart:
php artisan make:chart MedalsChart
This will generate a chart component within the View/Components
namespace.
<?php
namespace App\View\Components;
use Maartenpaauw\Chartscss\Chart;
use Maartenpaauw\Chartscss\Data\Axes\Axes;
use Maartenpaauw\Chartscss\Data\Datasets\Dataset;
use Maartenpaauw\Chartscss\Data\Datasets\Datasets;
use Maartenpaauw\Chartscss\Data\Datasets\DatasetsContract;
use Maartenpaauw\Chartscss\Data\Entries\Entry;
use Maartenpaauw\Chartscss\Data\Entries\Value\Value;
use Maartenpaauw\Chartscss\Data\Label\Label;
class MedalsChart extends Chart
{
protected function id(): string
{
return 'medals-chart';
}
protected function heading(): string
{
return __('Medals Chart');
}
protected function datasets(): DatasetsContract
{
return new Datasets(
new Axes('Country', ['Gold', 'Silver', 'Bronze']),
new Dataset([
new Entry(new Value(46)),
new Entry(new Value(37)),
new Entry(new Value(38)),
], new Label('USA')),
new Dataset([
new Entry(new Value(27)),
new Entry(new Value(23)),
new Entry(new Value(17)),
], new Label('GBR')),
new Dataset([
new Entry(new Value(26)),
new Entry(new Value(18)),
new Entry(new Value(26)),
], new Label('CHN')),
);
}
}
To display your chart it is as easily as adding the following blade component:
<x-medals-chart/>
Make sure you import the css library as well. There is a helper component available for it!
<x-charts-css-stylesheet cdn="unpkg" />