Transpose Process

This example shows the usage of Transpose process

PeterDavidJohn
5,000 3,000 4,000

->pipe(new Transpose())
c0c1
Peter 5000
David 3000
John 4000

The example demonstrates usage of Transpose process. As the name suggested, Transpose process turn the table 90 degree, making row to column and vice versa. The new column will be named from c0, c1 to cn.

If you want to rename column, you may use process ColumnRename

->pipe(new Transpose())
->pipe(new ColumnRename(array(
    "c0"=>"name"
    "c1"=>"contribution"
)))
<?php
require_once "MyReport.php";

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

use \koolreport\processes\ColumnMeta;
use \koolreport\processes\Transpose;

//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("Peter","David","John"),
                        array(5000,3000,4000),
                    )
                )
            )
        );
    }
    protected function setup()
    {
        //Prepare data
        $this->src("data")
        ->pipe(new ColumnMeta(array(
            "income"=>array(
                "type"=>"number",
                "prefix"=>"$"
            )
        )))
        ->saveTo($source);

        //Save orginal data
        $source->pipe($this->dataStore("origin"));
        
        //Pipe through process to get result
        $source->pipe(new Transpose())
        ->pipe($this->dataStore("result"));
    }
}
<?php
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\PieChart;
?>
<div class="report-content">
    <div class="text-center">
        <h1>Transpose Process</h1>
        <p class="lead">This example shows the usage of Transpose 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 Transpose())
</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"),
                "cssClass"=>array(
                    "table"=>"table-bordered table-striped table-hover"
                )
            ));
            ?>            
            </div>
            <div class="col-md-6">
            <?php
            PieChart::create(array(
                "dataSource"=>$this->dataStore("result"),
                "columns"=>array("c0","c1"),
                "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