AggregatedColumn Process

This example shows the usage of AggregatedColumn process

itemcost
Machines $50,000
Human Resource $60,000
Materials $100,000
Others $80,000

->pipe(new AggregatedColumn(array(
    "total_cost"=>array("sum","cost"),
    "average_cost"=>array("avg","cost"),
    "min_cost"=>array("min","cost"),
    "max_cost"=>array("max","cost"),
)))
itemcosttotal_costaverage_costmin_costmax_cost
Machines $50,000 $290,000 $72,500 $50,000 $100,000
Human Resource $60,000 $290,000 $72,500 $50,000 $100,000
Materials $100,000 $290,000 $72,500 $50,000 $100,000
Others $80,000 $290,000 $72,500 $50,000 $100,000

The example demonstrates usage of AggregatedColumn process. This process creates new column and fill in the aggregated value of an existed column. In above example, we generated 4 new columns total_cost, avg_cost, min_cost, max_cost.

<?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\AggregatedColumn;

//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("item","cost"),
                        array("Machines",50000),
                        array("Human Resource",60000),
                        array("Materials",100000),
                        array("Others",80000),
                    )
                )
            )
        );
    }
    protected function setup()
    {
        //Prepare data
        $this->src("data")
        ->pipe(new ColumnMeta(array(
            "cost"=>array(
                "type"=>"number",
                "prefix"=>"$"
            )
        )))
        ->saveTo($source);

        //Save orginal data
        $source->pipe($this->dataStore("origin"));
        
        //Pipe through process to get result
        $source->pipe(new AggregatedColumn(array(
            "total_cost"=>array("sum","cost"),
            "average_cost"=>array("avg","cost"),
            "min_cost"=>array("min","cost"),
            "max_cost"=>array("max","cost"),
        )))
        ->pipe(new ColumnMeta(array(
            "total_cost"=>array(
                "type"=>"number",
                "prefix"=>'$'
            ),
            "average_cost"=>array(
                "type"=>"number",
                "prefix"=>'$'
            ),
            "min_cost"=>array(
                "type"=>"number",
                "prefix"=>'$'
            ),
            "max_cost"=>array(
                "type"=>"number",
                "prefix"=>'$'
            ),
        )))
        ->pipe($this->dataStore("result"));
    }
}
<?php
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
    <div class="text-center">
        <h1>AggregatedColumn Process</h1>
        <p class="lead">This example shows the usage of AggregatedColumn 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 AggregatedColumn(array(
    "total_cost"=>array("sum","cost"),
    "average_cost"=>array("avg","cost"),
    "min_cost"=>array("min","cost"),
    "max_cost"=>array("max","cost"),
)))
</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>

</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