laraveldaily / laravel-charts Goto Github PK
View Code? Open in Web Editor NEWPackage to draw charts in Laravel with Chart.js
License: MIT License
Package to draw charts in Laravel with Chart.js
License: MIT License
For ex: I have posts with user_id. I want to show bars with user.name by their posts count.
Did instruction but not showing charts as istructed but no error. take chart area but showing nothing but h1 tag.
Hi!
I'm not sure what's going wrong here.
My chart is loading properly but is only showing the bottom condition.
$chartOptions = [
'chart_title' => 'Transactions by dates',
'chart_type' => 'line',
'report_type' => 'group_by_date',
'model' => 'App\Models\Transaction',
'conditions' => [
['name' => 'Debit', 'condition' => "!credit", 'color' => 'red', 'fill' => false],
['name' => 'Credit', 'condition' => "credit", 'color' => 'green', 'fill' => false],
],
'group_by_field' => 'date',
'group_by_period' => 'day',
'group_by_field_format' => 'Y-m-d',
'aggregate_function' => 'sum',
'aggregate_field' => 'amount',
];
$chart = new LaravelChart($chartOptions);
return view('home', compact('chart'));
Swapping the conditions will change the dataset from Credit to Debit and shows the new data in the chart with the corresponding color.
'conditions' => [
['name' => 'Debit', 'condition' => "!credit", 'color' => 'red', 'fill' => false],
['name' => 'Credit', 'condition' => "credit", 'color' => 'green', 'fill' => false],
],
Changing the condition to another property doesn't work either.
Dye and dumping the chart object does always show a single dataset.
Hey,
I want to create mixed chart.
Like this.
http://prntscr.com/o50nxi
Hi !
I didn't see anything in your repo about multiple dataset, is this something that we can do with your package? If yes can you explain how to do it ?
Thank you for this and for your videos ! :)
Hi,
i initially struggled to to set the correct datetime format when grouping by a datetime field. So i noticed in LaravelChart the undocumented group_by_field_format
LaravelChart.php Line 106
$this->options['group_by_field_format'] ?? 'Y-m-d H:i:s',
Could be useful for those using CET time settings or those who have model mutators otherwise the query will fail.
Is there away to customise / select specific colours for Pie Charts, currently it changes each time it is refreshed.
the chart is not rendering, but when I use dd (chart_name) I see that the object has the data I need, I'm just not getting it to appear in the desired view.
Can anyone help me with this problem?
Using version
laraveldaily / laravel-charts ^ 0.1.25
laravel 8.12
How do I use conditions like where in the model? Thx
i want to select my by this is my code
'where_raw' => 'transaction.id = (SELECT * FROM transactions INNER JOIN users ON users.id = transactions.payable_id)',
but did not return any data
pls how can i achieve this or correct code
When MultiTenantModel is used, then global scope is applied to the model.
However for displaying Charts in some cases I'd like to present data from all users.
SO implementing new option 'withoutGlobalScopes' could result in executing following query in LaravelCharts:
$collection = $query->withoutGlobalScopes()->get();
or - is there any other way to disable global scope?
how use where_raw ?
Hello,
I use SoftDelete on some Models.
How can I include this in my stats (to know the number of delete items) ?
Thanks !
$registerChart = new LaravelChart([
'chart_title' => 'Users',
'chart_type' => 'line',
'report_type' => 'group_by_date',
'model' => 'App\Models\User',
'group_by_field' => 'created_at',
'group_by_period' => 'day',
'aggregate_function' => 'count',
'filter_field' => 'created_at',
'filter_days' => '30',
'group_by_field_format' => 'Y-m-d H:i:s',
'column_class' => 'col-md-12',
'entries_number' => '5',
'translation_key' => 'user',
'continuous_time' => true,
]);
{!! $registerChart->renderHtml() !!}
@section('script')
{!! $registerChart->renderChartJsLibrary() !!}
{!! $registerChart->renderJs() !!}
@endsection
Is it possible to display amount currency, if so, how?
In LaravelChart.php line 53
[['name' => '', 'condition' => '', 'color' => '']];
change to
[['name' => '', 'condition' => "", 'color' => '']];
Because right it would accept only strings, I found it very useful when I can pass some variable data.
Chart still renders date range starting at first unfiltered record even when specifying filter_period
, range_date_start
and range_date_end
.
$params = [
"chart_title" => "Transactions"
"report_type" => "group_by_date"
"model" => "App\Models\Transaction",
"conditions" => array: [
0 => array: [
"name" => "Amount"
"condition" => "user_business_id = 13"
"color" => "#42C5D2"
"fill" => true
]
],
"group_by_field" => "created_at"
"group_by_period" => "day"
"chart_type" => "line"
"aggregate_function" => "sum"
"aggregate_field" => "amount"
"continuous_time" => true
"filter_field" => "created_at"
"filter_period" => "week"
"range_date_start" => "2021-10-25"
"range_date_end" => "2021-10-31"
]
$data['chart'] = new LaravelChart($params);
first the graph display correctly but when i load it first it works but when i update the variable
the graph is not display
Is it possible to get the data in an ajax request?
Thank you for this package.
I try to count the number of users in 30 days by day
But I found a problem
When there is only one user in 30 days, continuous_time doesn't work
When I add another user to the database with a different created_at, continuous_time works
php code
namespace App\Http\Controllers\Manager;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Http\Request;
use LaravelDaily\LaravelCharts\Classes\LaravelChart;
class StatisticsController extends Controller
{
public function index(Request $request)
{
$user_register_count = [
'all' => User::count(),
'30' => User::where([['created_at', '>=', date('Y-m-d H:i:s', time() - 2592000)]])->count(),
'7' => User::where([['created_at', '>=', date('Y-m-d H:i:s', time() - 604800)]])->count(),
'1' => User::where([['created_at', '>=', date('Y-m-d H:i:s', time() - 86400)]])->count(),
];
$chart_options = [
'chart_title' => 'user register for month',
'report_type' => 'group_by_date',
'model' => User::class,
'group_by_field' => 'created_at',
'group_by_period' => 'day',
'chart_type' => 'line',
'filter_days' => 30,
'continuous_time' => true,
];
$user_chart = new LaravelChart($chart_options);
return view('manager.statistics.index', [
'user_chart' => $user_chart,
'user_register_count' => $user_register_count,
]);
}
}
html code
<div class="chart">
{!! $user_chart->renderHtml() !!}
</div>
{!! $user_chart->renderChartJsLibrary() !!}
{!! $user_chart->renderJs() !!}
Currently I have the following options:
$chart_options = [
'chart_title' => 'Stats by dates',
'chart_type' => 'bar',
'report_type' => 'group_by_relationship',
'model' => 'App\Operator',
'relationship_name' => 'user',
'group_by_field' => 'name',
'filter_field' => 'completed_date',
'filter_days' => 1,
'filter_period' => 'week',
];
In date from model Operator I have a table item_clicked. I'd like to display
"where item_clicked == 'byname' ONLY and keep all the rest the same. Is there anyway to achieve custom queries for the data?
Hi,
I am trying to create a chart that shows how many users are active in a log table, daily.
I have one table logs with an "user" column that refers to the user/id, trying to get the results like running a DISTINCT(user_id)
I was trying with something like this but it shows the total numbers of records for each day, not grouping it by user. (es. i have 100 transactions of 5 different users, now i get 100 but i would like to get 5).
Is it possible?
$chart_options_daily_users = [
'chart_title' => 'Daily Users',
'chart_type' => 'line',
'report_type' => 'group_by_date',
'model' => 'App\ApiLog',
'conditions' => [
['name' => 'Users', 'condition' => '', 'color' => 'red'],
],
'relationship_name' => 'user',
'group_by_field' => 'name',
//'aggregate_function' => 'sum',
//'aggregate_field' => 'user',
'filter_field' => 'created_at',
'filter_days' => 30, // show only transactions for last 30 days
'filter_period' => 'month', // show only transactions for this week
'continuous_time' => false, // show continuous timeline including dates without data
];
Hello,
is there a way to optimize queries from this package?
Right now the query is "select * from table
" and I guess that is not good because if someone is using this for bigger projects where there might be 10k users the application will use 50MB of ram and there will also be 10k models loaded and wait time will be about 3-5s.
We just need numbers of rows related to "created_at" or something like that we don't need all columns.
Is it possible to make a selection of data by ID?
Purchases (user_id, amount, and etc)
How make chart only for user with ID = 1?
hi LaravelDaily Team
Laravel collection is a very bad idea if the table is a big amount of data
$collection = $query->get();
return error 500
Just a heads up, spatie library requires imagick to run, including Dashboard & Reports on an application, this returns an error after GIT download to local machine running on Windoze.
Symfony\Component\Debug\Exception\FatalThrowableError
Class 'LaravelDaily\LaravelCharts\Classes\LaravelChart' not found
So, I attempt an install of that package...
Windows 10 WAMP
$ composer require laraveldaily/laravel-charts
Using version ^0.1.13 for laraveldaily/laravel-charts
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- spatie/pdf-to-image 1.8.2 requires ext-imagick * -> the requested PHP extension imagick is missing from your system.
- spatie/pdf-to-image 1.8.2 requires ext-imagick * -> the requested PHP extension imagick is missing from your system.
- Installation request for spatie/pdf-to-image (locked at 1.8.2) -> satisfiable by spatie/pdf-to-image[1.8.2].
Really is a WAMP issue on Windows, but just a note that these users will run into the issue. Suggest alternative chart support in future development. Recommend a user include a non-CRUD blank menu item/view to implement their own Dashboard etc.
can i add a new color in chart?
Hi,
I have noticed that in a line graph, with multiple conditions, if two or more conditions have the same result number, only one shows in the graph while hover it.
I believe that if multiple conditions has the same result these shall be all listed in the hover tooltip of the chart.
this is my code .
[
'chart_title' => 'Click Report by dates',
'chart_type' => 'line',
'report_type' => 'group_by_date',
'model' => 'App\LinkClicks',
'conditions' => [
['name' => 'Link Clicks', 'condition' => 'publisher_post_id = ' . $this->post->id, 'color' => 'yellow', 'fill' => true],
],
'group_by_field' => 'created_at',
'group_by_period' => 'day',
'filter_field' => 'created_at',
'filter_days' => 30, // show only transactions for last 30 days
'continuous_time' => false,
'range_date_start' => $start_date,
'range_date_end' => $end_date,
];
Thank you.
How do i dynamically update the options and rerender the chart with the new options?
i got some issue that said "Undefined index: group_by_field_format"
i use field from my table that has the field type date but it doesnt work, when i changed it to type datetime field (created_at) the chart is working. i also try to group it by period of month
How do I change the date format? for example: created_at->format('d/m/Y')
Hi
Can you Add radar chart ?
Like this https://www.chartjs.org/docs/latest/samples/bar/stacked.html
Thank you for creating this awesome package !
Hi,
Line charts with multiple conditions should have all conditions to 0 on each day(or month or what so ever is selected) if theres no records for that conditions in the recordset.
Now this doesnt happen, if i do have 10 conditions, but the script can retrieve records only for 1, it doesnt show the other 9 with a "0 value", that should be the way it works i believe.
<canvas id="{{ $options['chart_name'] ?? 'myChart' }}"></canvas>
it would be interesting to have a new attribute
<canvas id="{{ $options['chart_name'] ?? 'myChart' }}" class="{{ $options['class_name'] }}"></canvas>
The Condition on Line Charts does not seem to be working properly...
.. 'chart_type' => 'line', 'conditions' => [ ['name' => 'Condition 1', 'condition' => 'field = value', 'color' => 'black'], ['name' => 'Condition 2', 'condition' => 'field2 = value2', 'color' => 'blue'], ], ...
However the code is generating a error:
Column not found: 1054 Unknown column 'value' in 'where clause' (SQL: select * from
tablewhere
created_at>= 2020-06-07 and field = value)
I am using the version 0.1.20 and the latest Laravel Version.
Please advise.
I have a model with some columns. I want a certain column to be used as the dataset and another column to be used on the x-axis as labels. I got the x-axis labels to work but can't seem to specifiy which column should be used in the model for the dataset. It now seems to be using the 'id' column on my model, I want to use the 'value' column instead. Here's my code.
$options = [
'chart_title' => 'Samplechart',
'chart_type' => 'line',
'model' => 'App\Models\Entry',
'condition' => [
['name' => 'value', 'condition' => 'user_id = {Auth::user()->id}', 'color' => 'black', 'fill' => 'true'],
],
'report_type' => 'group_by_date',
'group_by_field' => 'added_at',
'group_by_period' => 'day',
'group_by_field_format' => 'Y-m-d',
];
$chart = new LaravelChart($options);
Can someone tell me where in the docs this is specified or is this feature not supported?
Thanks!
Please how can i make +1 line in the same chart
i ran composer require laraveldaily/laravel-charts
and i got an error saying Target class [App\Providers\Charts] does not exist. Do i have to create the Charts class myself?
Hi there,
Is there currently a way to limit the number of groups pulled through and displayed on the chart (only show top 10 results)?
Thanks in advance for your response.
Hi,
If i enable continuous_time with a graph that works on a dataset with only the last 4 days set (its a log table) , it gives error:
"Invalid start date."
LaravelChart.php line 119
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.