LaravelDaily / laravel-charts

Package to draw charts in Laravel with Chart.js
MIT License
522 stars 116 forks source link

Shows only a single condition #79

Closed NSoes closed 2 years ago

NSoes commented 2 years ago

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.

PovilasKorop commented 2 years ago

@NSoes thanks for reporting, I've scheduled to the team to reproduce/fix this issue, but realistically only after New Year's.

krekas commented 2 years ago

@NSoes can you post your migration file? And what that condition credit should do?

NSoes commented 2 years ago

First of all best wishes for 2022!

@krekas I suppose you would like to see the migration file for the table which inherits the credit field: image Credit is a simple boolean which 'checks' if an amount is incoming or outgoing. The condition should separate the credit and debit values to show two different lines in the graph.

@PovilasKorop Thanks for taking the time to look into this issue! Currently, I'm plotting two different graphs for incoming and outgoing transactions. This does work, but isn't preferred.

krekas commented 2 years ago

@NSoes now you can use multiple datasets code will be longer but at least result as expected