LaravelDaily / laravel-charts

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

Multiple dataset from same Model but grouped by a foreign key #117

Open CarterSnich opened 11 months ago

CarterSnich commented 11 months ago

So, I have a Student model that has section_id column. I was able to create a line graph that shows number of enrollments every year. Now, I want to make multiple lines for each section_id. How can I achieve this? Also, how can I make the Y numbers as whole numbers and ranges only to available data. Example, the max data is 10 and min is 3, the Y numbers should only show range from 3 to 10. image

Controller

 $apple = [
        'chart_title' => 'Apple',
        'report_type' => 'group_by_date',
        'model' => 'App\Models\Student',
        'group_by_field' => 'created_at',
        'group_by_period' => 'year',
        'chart_type' => 'line',

    ];
    $orange = [
        'chart_title' => 'Orange',
        'report_type' => 'group_by_date',
        'model' => 'App\Models\Student',
        'group_by_field' => 'created_at',
        'group_by_period' => 'year',
        'chart_type' => 'line',
    ];
   $mango = [...];

    $chart = new LaravelChart($apple, $orange, $mango);

Model

class Student extends Model
{
    use HasFactory;

    protected $fillable = [
        'student_id',
        'firstname',
        'lastname',
        'middlename',
        'birthdate',
        'section_id' // foreign key
    ];
}
CarterSnich commented 11 months ago

I'm sorry that this just become a more of a help instead of a bug report.