Multiple dataset from same Model but grouped by a foreign key
Opened this issue · 1 comments
CarterSnich commented
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.
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
I'm sorry that this just become a more of a help instead of a bug report.