Download the PHP package tpharaoh/laravel-charts without Composer
On this page you can find all versions of the php package tpharaoh/laravel-charts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tpharaoh/laravel-charts
More information about tpharaoh/laravel-charts
Files in tpharaoh/laravel-charts
Package laravel-charts
Short Description Create charts and reports from Laravel
License MIT
Informations about the package laravel-charts
Laravel Charts
Package to generate Chart.js charts directly from Laravel/Blade, without interacting with JavaScript.
Notice: Package is in early development, generating simple cases, so it's likely that syntax/parameters will change with future versions, use with cautions.
Simple Usage
If you want to generate a chart above, grouping users records by the month of __created_at__ value, here's the code.
Controller:
View File
Installation
No additional configuration or other parameters yet.
Usage
You need to create LaravelChart
object in your Controller, passing array of options.
Then pass it to the View, as a variable:
Available Reports and Options
Currently package support two types of charts/reports:
group_by_date
- amount of records from the same table, grouped by time period - day/week/month/year;group_by_string
- amount of records from the same table, grouped by any string field, likename
;group_by_relationship
- amount of records from the same table, grouped bybelongsTo
relationship's field
Example with all options
chart_title
(required) - just a text title that will be shown as legend;chart_type
(required) - possible values: "line", "bar", "pie";report_type
(required) - see above, can begroup_by_date
,group_by_string
orgroup_by_relationship
;model
(required) - name of Eloquent model, where to take the data from;group_by_field
(required) - name of database field that will be used ingroup_by
clause;group_by_period
(optional, only forgroup_by_date
report type) - possible values are "day", "week", "month", "year";relationship_name
(optional, only forgroup_by_relationship
report type) - the name of model's method that containsbelongsTo
relationship.aggregate_function
(optional) - you can view not only amount of records, but also theirSUM()
orAVG()
. Possible values: "count" (default), "avg", "sum".aggregate_field
(optional) - seeaggregate_function
above, the name of the field to use inSUM()
orAVG()
functions. Irrelevant forCOUNT()
.filter_field
(optional) - show only data filtered by that datetime field (see below)filter_days
(optional) - seefilter_field
above - show only lastfilter_days
days of that field. Example, last 30 days bycreated_at
field.filter_period
(optional) - another way to filter by field, show only record from last week / month / year. Possible values are "week", "month", "year".-
continuous_time
(optional) - show all dates on chart, including dates without data. -
Example with relationship
Notice: currently package is in early version, so these parameters may change in the future.
Rendering Charts in Blade
After you passed $chart
variable, into Blade, you can render it, by doing three actions:
Action 1. Render HTML.
Wherever in your Blade, call this:
It will generate something like this:
Action 2. Render JavaScript Library
Package is using Chart.js library, so we need to initialize it somewhere in scripts section:
It will generate something like this:
Action 3. Render JavaScript of Specific Chart
After Chart.js is loaded, launch this:
Using Multiple Charts
You can show multiple charts on the same page, initialize them separately.
Controller:
View:
License
The MIT License (MIT). Please see License File for more information.
More from our LaravelDaily Team
- Read our Daily Blog with Laravel Tutorials
- FREE E-book: 50 Laravel Quick Tips (and counting)
- Check out our adminpanel generator QuickAdminPanel: Laravel version and Vue.js version
- Subscribe to our YouTube channel Laravel Business
- Enroll in our Laravel Online Courses