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 "../../../../koolreport/autoload.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
    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 6,067
2003-06-05 14,571
2004-12-18 1,676
2004-12-17 14,191
2003-06-06 32,642
2004-08-20 33,348
2003-05-20 45,864
2004-12-15 82,261
2003-05-31 7,565
2004-03-10 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