Sale By Month
This example shows you how to setup a DrillThrough
or MultiView
report, viewing
data in different kinds of charts.
Payment Time | Amount |
---|---|
Jan 2003 | $26,268 |
Feb 2003 | $144,384 |
Mar 2003 | $199,704 |
Apr 2003 | $136,314 |
May 2003 | $159,882 |
Jun 2003 | $180,219 |
Jul 2003 | $158,247 |
Aug 2003 | $246,205 |
Sep 2003 | $161,206 |
Oct 2003 | $316,858 |
Nov 2003 | $694,293 |
Dec 2003 | $826,638 |
Jan 2004 | $234,152 |
Feb 2004 | $106,652 |
Mar 2004 | $404,603 |
Apr 2004 | $173,246 |
May 2004 | $208,524 |
Jun 2004 | $185,843 |
Jul 2004 | $284,191 |
Aug 2004 | $378,094 |
Sep 2004 | $476,446 |
Oct 2004 | $185,103 |
Nov 2004 | $857,187 |
Dec 2004 | $819,286 |
Jan 2005 | $137,468 |
Feb 2005 | $252,321 |
Mar 2005 | $385,268 |
Apr 2005 | $183,898 |
May 2005 | $272,249 |
Jun 2005 | $59,089 |
MultiView
and DrillThrough
are the same type of report. It represents same data in different types of charts so that we can have a better feel of data. For example, the sale data can be displayed in tabular format or column chart or heatmap of your choice.
In above example, the sale by month is represented in ColumnChart, LineChart and Tabular format.
The more information of MultiView widget including its documentation you may find in the DrillDown package.
<?php
require_once "../../../load.koolreport.php";
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
use \koolreport\processes\TimeBucket;
use \koolreport\processes\Group;
class MyReport extends \koolreport\KoolReport
{
function settings()
{
return array(
"dataSources"=>array(
"automaker"=>array(
"connectionString"=>"mysql:host=localhost;dbname=automaker",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
),
)
);
}
function setup()
{
$this->src("automaker")->query("
select paymentDate, amount from payments
")
->pipe(new TimeBucket(array(
"paymentDate"=>"month",
)))
->pipe(new Group(array(
"by"=>"paymentDate",
"sum"=>"amount",
)))
->pipe($this->dataStore("sale"));
}
}
<?php
use \koolreport\drilldown\MultiView;
use \koolreport\processes\CopyColumn;
use \koolreport\processes\DateTimeFormat;
use \koolreport\widgets\google\LineChart;
use \koolreport\widgets\google\ColumnChart;
use \koolreport\widgets\koolphp\Table;
?>
<div class="report-content">
<div class="text-center">
<h1>Sale By Month</h1>
<p class="lead">
This example shows you how to setup a <code>DrillThrough</code> or <code>MultiView</code> report, viewing
data in different kinds of charts.
</p>
</div>
<?php
// $data = array_slice($this->dataStore("sale")->data(), 0, 10);
// echo "<pre>" . var_export($data) . "</pre>";
// $data = array(
// array('paymentDate' => '2003-01', 'amount' => 26267.620000000003),
// array('paymentDate' => '2003-02', 'amount' => 144384.36),
// array('paymentDate' => '2003-03', 'amount' => 199704.47999999998),
// array('paymentDate' => '2003-04', 'amount' => 136313.91999999998),
// array('paymentDate' => '2003-05', 'amount' => 159881.97000000003),
// array('paymentDate' => '2003-06', 'amount' => 180218.97999999998),
// array('paymentDate' => '2003-07', 'amount' => 158247.0),
// array('paymentDate' => '2003-08', 'amount' => 246204.86),
// array('paymentDate' => '2003-09', 'amount' => 161206.22999999998),
// array('paymentDate' => '2003-10', 'amount' => 316857.96),
// );
MultiView::create(array(
"name" => "saleMultiView",
"dataSource" => $this->dataStore("sale"),
"title" => "Sale By Month",
"views" => array(
array(
"handler" => "<i class='fa fa-line-chart'></i>",
"widget" => array(LineChart::class, array(
"columns" => array(
"paymentDate" => array(
"label" => "Payment Time",
"type" => "datetime",
"format" => "Y-m",
"displayFormat" => "M Y",
),
"amount" => array(
"prefix" => '$',
"label" => "Amount"
)
)
))
),
array(
"handler" => "<i class='fa fa-bar-chart'></i>",
"widget" => array(ColumnChart::class, array(
"columns" => array(
"paymentDate" => array(
"label" => "Payment Time",
"type" => "datetime",
"format" => "Y-m",
"displayFormat" => "M Y",
),
"amount" => array(
"prefix" => '$',
"label" => "Amount"
)
)
))
),
array(
"handler" => "<i class='fa fa-table'></i>",
"widget" => array(Table::class, array(
"columns" => array(
"paymentDate" => array(
"label" => "Payment Time",
"type" => "datetime",
"format" => "Y-m",
"displayFormat" => "M Y",
),
"amount" => array(
"prefix" => '$',
"label" => "Amount"
)
),
"paging" => array(
"pageSize" => 10,
)
))
),
)
));
?>
</div>
paymentDate | amount |
---|---|
2004-10-19 00:00:00 | 6,067 |
2003-06-05 00:00:00 | 14,571 |
2004-12-18 00:00:00 | 1,676 |
2004-12-17 00:00:00 | 14,191 |
2003-06-06 00:00:00 | 32,642 |
2004-08-20 00:00:00 | 33,348 |
2003-05-20 00:00:00 | 45,864 |
2004-12-15 00:00:00 | 82,261 |
2003-05-31 00:00:00 | 7,565 |
2004-03-10 00:00:00 | 44,895 |
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