NumberRange Process

This example shows the usage of NumberRange process

namecharity
John $5
Marry $13
Peter $15
David $10
Jane $20
Donald $50
Them $60
Smith $10
Johny $17
Michael $90
Jolie $65
Bradpit $45
Eddie $35

->pipe(new NumberRange(array(
    "charity"=>array(
        "Low"=>array(null,20),
        "Medium"=>array(20,50),
        "High"=>array(50,null),
    )
)))
namecharity
John Low
Marry Low
Peter Low
David Low
Jane Medium
Donald High
Them High
Smith Low
Johny Low
Michael High
Jolie High
Bradpit Medium
Eddie Medium

->pipe(new Group(array(
    "by"=>"charity",
    "count"=>"count"
)))
charitycount
High 4
Low 6
Medium 3

The example demonstrates usage of NumberRange process. The NumberRange let you define custom name for a range. Like in above example, we define charity amount less than $20 is Low, from 20 to less than 50 is Medium and higher or equal to $50 is High.

The NumberRange is normally used with Group process as above example showing.

<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";

use \koolreport\processes\ColumnMeta;
use \koolreport\processes\NumberRange;
use \koolreport\processes\Group;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>array(
                        array("name","charity"),
                        array("John",5),
                        array("Marry",13),
                        array("Peter",15),
                        array("David",10),
                        array("Jane",20),
                        array("Donald",50),
                        array("Them",60),
                        array("Smith",10),
                        array("Johny",17),
                        array("Michael",90),
                        array("Jolie",65),
                        array("Bradpit",45),
                        array("Eddie",35),
                    )
                )
            )
        );
    }
    protected function setup()
    {
        //Prepare data
        $this->src("data")
        ->pipe(new ColumnMeta(array(
            "charity"=>array(
                "type"=>"number",
                "prefix"=>"$"
            )
        )))
        ->saveTo($source);

        //Save orginal data
        $source->pipe($this->dataStore("origin"));
        
        //Pipe through process to get result
        $source->pipe(new NumberRange(array(
            "charity"=>array(
                "Low"=>array(null,20),
                "Medium"=>array(20,50),
                "High"=>array(50,null),
            )
        )))->saveTo($result)
        ->pipe($this->dataStore("result"));
    
        $result->pipe(new Group(array(
            "by"=>"charity",
            "count"=>"count"
        )))
        ->pipe($this->dataStore("result_further"));
    }
}
<?php
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\PieChart;
?>
<div class="report-content">
    <div class="text-center">
        <h1>NumberRange Process</h1>
        <p class="lead">This example shows the usage of NumberRange process</p>
    </div>
    
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("origin"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>

<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new NumberRange(array(
    "charity"=>array(
        "Low"=>array(null,20),
        "Medium"=>array(20,50),
        "High"=>array(50,null),
    )
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>

    <div style="margin-top:20px;">
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("result"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>
    </div>

<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new Group(array(
    "by"=>"charity",
    "count"=>"count"
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>

    <div style="margin-top:20px;">
    <div class="row">
        <div class="col-md-6">
            <?php
            Table::create(array(
                "dataSource"=>$this->dataStore("result_further"),
                "columns"=>array("charity","count"),
                "cssClass"=>array(
                    "table"=>"table-bordered table-striped table-hover"
                )
            ));
            ?>
        </div>
        <div class="col-md-6">
            <?php
            PieChart::create(array(
                "dataSource"=>$this->dataStore("result_further"),
                "columns"=>array("charity","count"),
                "options"=>array(
                    "legend"=>array(
                        "position"=>"right"
                    ),
                    "chartArea"=>array(
                        "top"=>10,
                        "left"=>0,
                        "right"=>0
                    )
                )
            ));
            ?>
        </div>

    </div>
    </div>



</div>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro