KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Single Query Multiple Charts #3343

Open Sabri opened this topic on on Sep 24 - 1 comments

Sabri commented on Sep 24

Hi,

Currently I have 4 different files for each card (first quarter...fourth quarter)

This is my code for FirstQuarterText.php (I created four different files with similar query. different is in the WHERE clause QUARTER(register_date) ` class FirstQuarterText extends SimpleCard {

protected function onCreated()
{   
    $this
    ->type("warning")
    ->text("First Quarter")
    ->icon("fa fa-battery-three-quarters");
}

protected function value()
{
    return myDatabase::rawSQL("
       SELECT COUNT(id)
       FROM student
       WHERE QUARTER(register_date) = 1
    ")->run()->getScalar();
}

} ` This code from Dashboard.php

Row::create([
    FirstQuarterText::create()->width(1/4),
    SecondQuarterText::create()->width(1/4),
    ThirdQuarterText::create()->width(1/4),
    FourthQuarterText::create()->width(1/4),
]),    

Is it possible for me to use just a single file OR single query that can display in 4 different card/chart

           SELECT COUNT(id), QUARTER(register_date)
           FROM student
           WHERE QUARTER(register_date) = 1
           GROUP BY QUARTER(register_date)
Sebastian Morales commented on Sep 25

You can write a single parent class that get 4 quarter results from a single sql query and set its to an array property.

Then create 4 sub classes which are different only in function value() which returns corresponding quarter result from the array property.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None