The example demonstrates usage of NumberBucket
process. The NumberBucket will create a number of buckets with same size to put number into. A bucket is defined as "{from} - {to}"
format, for example: "0-20"
, "20-40"
.
The NumberBucket takes the "step"
a must-have property. This is actually the size of a bucket. Beside the "step"
, there are several optional settings such as "prefix"
, "suffix"
, "thousandSeparator"
, "decimals"
and "decimalPoint"
. Those are actually the settings to format number.
<?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\NumberBucket;
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 NumberBucket(array(
"charity"=>array(
"step"=>20,
"prefix"=>"$"
)
)))->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>NumberBucket Process</h1>
<p class="lead">This example shows the usage of NumberBucket 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 NumberBucket(array(
"charity"=>array(
"step"=>20,
"prefix"=>"$"
)
)))
</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>