Array Data

This report show how to build report from Array data

ItemAmount
Accessories $8,000
Human Resource $20,000
Machine $40,000
Material $70,000

KoolReport has built in array datasource which is able to get data from array to produce report. In above example we create an report which will take array as parameter. The data from array will be sent to report to process and produce result.

<?php 

require_once "MyReport.php";
$report = new MyReport(array(
    "data"=>array(
        array("Item","Cost"),
        array("Accessories",3000),
        array("Human Resource",20000),
        array("Material",50000),
        array("Machine",30000),
        array("Accessories",5000),
        array("Machine",10000),
        array("Material",20000),
    )
));
$report->run()->render();
<?php

require_once "../../../load.koolreport.php";

use \koolreport\KoolReport;
use \koolreport\processes\Group;

class MyReport extends KoolReport
{
    public function settings()
    {
        return array(
            "dataSources" => array(
                "paramData" => array(
                    "class" => '\koolreport\datasources\ArrayDataSource',
                    "data" => $this->params["data"],
                    "dataFormat" => "table",
                ),
                "directTableData" => array(
                    "class" => '\koolreport\datasources\ArrayDataSource',
                    "dataFormat" => "table",
                    "data" => array(
                        array("Item", "Cost"),
                        array("Accessories", 3000),
                        array("Human Resource", 20000),
                        array("Material", 50000),
                        array("Machine", 30000),
                        array("Accessories", 5000),
                        array("Machine", 10000),
                        array("Material", 20000),
                    ),
                ),
                "directAssociateData" => array(
                    "class" => '\koolreport\datasources\ArrayDataSource',
                    "dataFormat" => "associate",
                    "data" => array(
                        array("Item" => "Accessories", "Cost" => 3000),
                        array("Item" => "Human Resource", "Cost" => 20000),
                        array("Item" => "Material", "Cost" => 50000),
                        array("Item" => "Machine", "Cost" => 30000),
                        array("Item" => "Accessories", "Cost" => 5000),
                        array("Item" => "Machine", "Cost" => 10000),
                        array("Item" => "Material", "Cost" => 20000),
                    ),
                ),
            )
        );
    }
    protected function setup()
    {
        $this->src('directAssociateData')
            ->pipe(new Group(array(
                "by" => "Item",
                "sum" => "Cost",
            )))
            ->pipe($this->dataStore('cost'));
    }
}
<?php 
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\PieChart;
?>

<div class='report-content'>
    <div class="text-center">
        <h1>Array Data</h1>
        <p class="lead">This report show how to build report from Array data</p>
    </div>

    <?php
    PieChart::create(array(
        "dataStore"=>$this->dataStore('cost'),  
        "columns"=>array(
            "Item",
            "Cost"=>array(
                "label"=>"Amount",
                "type"=>"number",
                "prefix"=>"$",
            )
        ),
        "width"=>"100%",
    ));
    ?>

    <?php
    Table::create(array(
        "dataStore"=>$this->dataStore('cost'),
        "columns"=>array(
            "Item",
            "Cost"=>array(
                "label"=>"Amount",
                "type"=>"number",
                "prefix"=>"$",
            )
        ),
        "cssClass"=>array(
            "table"=>"table table-hover table-bordered"
        )
    ));
    ?>
</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

Download KoolReport Get KoolReport Pro