The example demonstrates usage of AccumulativeColumn
process. The AccumulativeColumn creates new column from existed column and generate running total for that existed column. You can see in above example, spent
is what we spent on a day and new running_total
is the toal money we have spent until that day.
<?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\AccumulativeColumn;
//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("date","spent"),
array("2018-09-01",142),
array("2018-09-02",90),
array("2018-09-03",123),
array("2018-09-04",164),
array("2018-09-05",423),
array("2018-09-06",343),
)
)
)
);
}
protected function setup()
{
//Prepare data
$this->src("data")
->pipe(new ColumnMeta(array(
"spent"=>array(
"type"=>"number",
"prefix"=>"$"
)
)))
->saveTo($source);
//Save orginal data
$source->pipe($this->dataStore("origin"));
//Pipe through process to get result
$source->pipe(new AccumulativeColumn(array(
"running_total"=>"spent"
)))
->pipe($this->dataStore("result"));
}
}
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
<div class="text-center">
<h1>AccumulativeColumn</h1>
<p class="lead">This example shows the usage of AccumulativeColumn 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 AccumulativeColumn(array(
"running_total"=>"spent"
)))
</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>