# NumberBucket Process

This example shows the usage of NumberBucket process

namecharity
John \$5
Marry \$13
Peter \$15
David \$10
Jane \$20
Donald \$50
Them \$60
Smith \$10
Johny \$17
Michael \$90
Jolie \$65
Eddie \$35
``````
->pipe(new NumberBucket(array(
"charity"=>array(
"step"=>20,
"prefix"=>"\$"
)
)))
``````
namecharity
John \$0 - \$20
Marry \$0 - \$20
Peter \$0 - \$20
David \$0 - \$20
Jane \$20 - \$40
Donald \$40 - \$60
Them \$60 - \$80
Smith \$0 - \$20
Johny \$0 - \$20
Michael \$80 - \$100
Jolie \$60 - \$80
Eddie \$20 - \$40
``````
->pipe(new Group(array(
"by"=>"charity",
"count"=>"count"
)))
``````
charitycount
\$0 - \$20 6
\$20 - \$40 2
\$40 - \$60 2
\$60 - \$80 2
\$80 - \$100 1

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

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("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;
?>
<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>``````

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