Sale By Month

This example shows you how to setup a DrillThrough or MultiView report, viewing data in different kinds of charts.

Sale By Month

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

Download KoolReport Get KoolReport Pro