KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

No data displayed in PivotMatrix #710

Closed CAURAT opened this topic on on Feb 26, 2019 - 10 comments

CAURAT commented on Feb 26, 2019

Hi,

I am trying to build a simple PivotMatrix using koolreport pro 3.25.4. However I could not get any data in the DataStore and PivotMatrix. Please help.

in DCSP_TestReport.php


<?php
require_once "./koolreport/autoload.php";

use \koolreport\processes\Filter;
use \koolreport\processes\ColumnMeta;
use \koolreport\pivot\processes\Pivot;

class DCSP_TestReport extends \koolreport\KoolReport
{
	use \koolreport\clients\jQuery;
		
    public function settings()
    {
		$server         = "xxxxxx";
		$db_username    = "xxxxxx";
		$db_password    = "xxxxxx";
		$service_name   = "xxxxxx";
		$sid            = "xxxxxx";
		$port           = xxxx;
		$dbtns          = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = $server)(PORT = $port)) (CONNECT_DATA = (SERVICE_NAME = $service_name) (SID = $sid)))";

        return array(
            "dataSources"=>array(
                "dcsp"=>array(
                    "connectionString"=>"oci:dbname=" . $dbtns . ";charset=utf8",
                    "username"=>"$db_username",
                    "password"=>"$db_password",
                )
            )
        );
    }

    public function setup()  {
		$sql = "select 'CAR' change_type,'01/01/2019' as export_week, 2 as chg_qty from dual
			union all
			select 'CAR' change_type,'01/01/2019' as export_week, 3 as chg_qty from dual
			union all
			select 'CAR' change_type,'08/01/2019' as export_week, 3 as chg_qty from dual
			union all
			select 'VAN' change_type,'01/01/2019' as export_week, 5 as chg_qty from dual
			union all
			select 'VAN' change_type,'08/01/2019' as export_week, 4 as chg_qty from dual
			union all
			select 'BIKE' change_type,'01/01/2019' as export_week, 1 as chg_qty from dual
			";

        $node = $this->src('dcsp')
			->query($sql)
			->pipe(new ColumnMeta(array(
                    	"change_type" => array(
                        	'label' => 'Change Type',
							'type'  => 'string',
						),
						"export_week" => array(
                        	'label' => 'Export Week',
							'type'  => 'string',
						),
						"chg_qty" => array(
							'type' => 'number',
						),
					)))  

		->pipe( new Pivot (array(
			"dimensions" => array(
				"column" => "export_week",
				"row" => "change_type",
			),
			"aggregates"=>array(
				"sum" => "chg_qty"
			)
        )))
		
        ->pipe($this->dataStore('OMR'));		
    }
}
?>

in DCSP_TestReport.view.php


<?php 
	use \koolreport\pivot\widgets\PivotMatrix;
	use \koolreport\core\Utility;
	use \koolreport\processes\Filter;
	use \koolreport\processes\ColumnMeta;
	use \koolreport\pivot\processes\Pivot;
	use \koolreport\instant\Widget;
?>
<form id='form1' class="form-inline" method="post">
<?php
	
	// if($this->dataStore('OMR')->countData()>0) {
		
		PivotMatrix::create(array(
			"id" => "pivotMatrix1",
			"dataStore"=>$this->dataStore('OMR'),
			'rowDimension'=>'row',
			'columnDimension'=>'column',
			'measures' => array("chg_qty - sum"),
			'paging' => array(),
		));
		
	// }
?>
</form>

This is the result that I am getting.

David Winterburn commented on Feb 26, 2019

Hi CAURAT,

It seems your sql query is misconstructed and doesn't return any data for pivot. Please copy your query to your database interface and test it to make sure it's correct. Thanks!

CAURAT commented on Feb 26, 2019

The sql is working fine on my database. If I were to run the same with DataTables, I am able to see the results. It is just not working with PivotMatrix.

$node01 = $this->src('dcsp')
			->query($sql)
			->pipe($this->dataStore('OMR2'));
DataTables::create(array(
    "dataStore"=>$this->dataStore('OMR2'),
	"options"=>array(
		"searching"=>true,
		"paging"=>true,
		"select"=>true,
	)
));
David Winterburn commented on Feb 26, 2019

Hi CAURAT,

It seems strange. I've tested your code and the PivotMatrix shows the data allright. Please change your sql to this and test it again:

$sql = "select 'CAR' change_type,'01/01/2019' as export_week, 2 as chg_qty
			union all
			select 'CAR' change_type,'01/01/2019' as export_week, 3 as chg_qty
			union all
			select 'CAR' change_type,'08/01/2019' as export_week, 3 as chg_qty
			union all
			select 'VAN' change_type,'01/01/2019' as export_week, 5 as chg_qty
			union all
			select 'VAN' change_type,'08/01/2019' as export_week, 4 as chg_qty
			union all
			select 'BIKE' change_type,'01/01/2019' as export_week, 1 as chg_qty";

Thanks!

CAURAT commented on Feb 26, 2019

Hi David.

I am connected to an Oracle database and without the 'from table', i am getting an OCI error. Fatal error: Uncaught Exception: Query Error >> [OCIStmtExecute: ORA-00923: FROM keyword not found where expected (ext\pdo_oci\oci_statement.c:157)]

Does the PivotMatrix require internet connection to work? My server is on intranet by the way.

David Winterburn commented on Feb 26, 2019

Hi CAURAT,

Our Pivot package doesn't need Internet to work. It's totally offline. Please try the following code and let me know the result:

$this->src('dcsp')
			->query($sql)
			->pipe( new Pivot (array(
			"dimensions" => array(
				"column" => null,
				"row" => null
			),
			"aggregates"=>array(
				"sum" => "chg_qty"
			)
        )))
->pipe($this->dataStore('OMR'));

Thanks!

CAURAT commented on Feb 26, 2019

Hi David,

David Winterburn commented on Feb 26, 2019

Hi CAURAT,

Please show the full PivotMatrix, does the Total cell show any number? Thanks!

CAURAT commented on Feb 26, 2019

No numbers on the total cell.

David Winterburn commented on Feb 26, 2019

Hi CAURAT,

It seems that by default Oracle returns data with all field names in upper case. Please change all the fields in your code to 'CHANGE_TYPE', 'EXPORT_WEEK', 'CHG_QTY' and 'CHG_QTY - sum' to see if it solves the problem. Thanks!

CAURAT commented on Feb 26, 2019

Splendid! It works perfectly after changing it to upper case. Thank you so much for your help David.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Pivot