Git Product home page Git Product logo

laravel-charts's Issues

Shows only a single condition

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.

Multiple Dataset in one chart ?

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 ! :)

group_by_field_format missing in documentation

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.

Select Colours on Pie charts

Is there away to customise / select specific colours for Pie Charts, currently it changes each time it is refreshed.

the chart is not rendering

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 to use join

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

Options to skip globalScode

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?

Include SoftDelete

Hello,
I use SoftDelete on some Models.
How can I include this in my stats (to know the number of delete items) ?
Thanks !

A two digit month could not be found Data missing

image

In My Controller

        $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,
        ]);

In My Blade

{!! $registerChart->renderHtml() !!}
@section('script')
{!! $registerChart->renderChartJsLibrary() !!}
{!! $registerChart->renderJs() !!}
@endsection

Change quotation mark to double for the condition

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.

Date range not working

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);

image

Ajax

Is it possible to get the data in an ajax request?

Thank you for this package.

When the statistical target has only one piece of data, continuous_time doesn't work

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() !!}

image

Relationship and also group by specific table

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?

Group by field

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
        ];

Optimization

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.

Sampling data by value

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?

Fails if imagick extension not installed

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.

Multiple records with same result doesnt show

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.

start date end date not working

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.

Quick Question

How do i dynamically update the options and rerender the chart with the new options?

unable to group_by_field with a field type date

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

Line charts and conditions issue

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.

How to assign a style class to the canvas?

<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>

Column not found

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 tablewherecreated_at>= 2020-06-07 and field = value)

I am using the version 0.1.20 and the latest Laravel Version.

Please advise.

How to specify which column in model should be used as dataset?

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!

continuous_time gives error

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.