KoolReport's Forum

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

Array_keys() expects parameter 1 to be array #2664

Open Suma Gowda opened this topic on on May 10 - 13 comments

Suma Gowda commented on May 10

Am trying to design Charts using tool. Getting below error message:

Warning: array_keys() expects parameter 1 to be array, null given in C:\xampp\htdocs\KoolReport\get__start\vendor\koolreport\core\src\widgets\google\Chart.php on line 167

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\KoolReport\get__start\vendor\koolreport\core\src\widgets\google\Chart.php on line 168

Warning: array_keys() expects parameter 1 to be array, null given in C:\xampp\htdocs\KoolReport\get__start\vendor\koolreport\core\src\widgets\google\Chart.php on line 167

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\KoolReport\get__start\vendor\koolreport\core\src\widgets\google\Chart.php on line 168 Table has no columns.×

Please can you guide me.

Sebastian Morales commented on May 11

Hi, pls post your report's setup and view code for us to check it for you. This looks like your chart doesn't have a datasource/datastore object.

Suma Gowda commented on May 11

Hello Morales,

Please check the below code.

index.php

<?php
require_once "../vendor/autoload.php";
require_once "SaleReport.php";

$report = new SaleReport;
$report->run()->render();



SaleReport.php

<?php
require_once "../vendor/autoload.php";
use \koolreport\processes\Group;
use \koolreport\processes\Sort;
use \koolreport\processes\Limit;

class SaleReport extends \koolreport\KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "automaker"=>array(
                    "connectionString"=>"mysql:host=localhost;dbname=automaker",
                    "username"=>"root",
                    "password"=>"",
                    "charset"=>"utf8"
                )
            )
        );
    }

    public function setup()
    {
        $this->src('automaker')
        ->query("SELECT customers.customerName,sum(payments.amount) as SaleAmount
         FROM payments
         JOIN customers ON customers.customerNumber = payments.customerNumber
         GROUP BY customers.customerName 
         LIMIT 10
         ")
        // ->pipe(new Group(array(
        //     "by"=>"customerName",
        //     "sum"=>"dollar_sales"
        // )))
        // ->pipe(new Sort(array(
        //     "dollar_sales"=>"desc"
        // )))
        // ->pipe(new Limit(array(10)))
        ->pipe($this->dataStore('result'));
    }
}

SaleReport.view.php

<?php 
    use \koolreport\clients\Bootstrap;
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\BarChart;
?>

<div class="text-center">
    <h1>Sales Report</h1>
    <h4>This report shows top 10 sales by customer</h4>
</div>
<hr/>

<?php
 BarChart::create(array(
    "dataStore"=>$this->dataStore('result')));

?>
<?php
Table::create(array(
    "dataStore"=>$this->dataStore('result')
));
?>

Sebastian Morales commented on May 11

Thank you. It seems there's a bug with Google chart when no columns are defined. To fix it at the moment pls set your chart's columns like this:

<?php
 BarChart::create(array(
    "dataStore"=>$this->dataStore('result')
    "columns" => array(
        "customerName" => [],
        "SaleAmount" => []
    )
));
?>

We will make a fix so that Google chart can work with default columns of its datastore. Rgds,

Suma Gowda commented on May 11

Thank you Morales. Array error message is fixed now. But am not able to see the graph data.

<?php 
    use \koolreport\clients\Bootstrap;
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\BarChart;
?>

<div class="text-center">
    <h1>Sales Report</h1>
    <h4>This report shows top 10 sales by customer</h4>
</div>
<!-- <hr/> -->

<?php
Table::create(array(
    "dataStore"=>$this->dataStore('result'),
        "columns"=>array(
            "customerName"=>array(
                "label"=>"Customer"
            ),
            "SaleAmount"=>array(
                "type"=>"number",
                "label"=>"Amount",
                "prefix"=>"$",
            )
        ),
    "cssClass"=>array(
        "table"=>"table table-hover table-bordered"
    )
));
?>

<?php
 BarChart::create(array(
    "dataStore"=>$this->dataStore('result'),
    "columns" => array(
        "customerName" => [],
        "SaleAmount" => []
    )
    // "columns"=>array(
    //             "customerName"=>array(
    //                 "label"=>"Customer"
    //             ),
    //             "SaleAmount"=>array(
    //                 "type"=>"number",
    //                 "label"=>"Amount",
    //                 "prefix"=>"$",
    //             )
    //         ),
));
?>

Anything i missed here, please suggest me on this.

Sebastian Morales commented on May 11

Pls try BarChart with this columns settting:

 BarChart::create(array(
        "dataStore"=>$this->dataStore('result'),
        "columns"=>array(
            "customerName"=>array(
                "label"=>"Customer"
            ),
            "SaleAmount"=>array(
                "type"=>"number",
                "label"=>"Amount",
                "prefix"=>"$",
            )
        ), 
));

If chart still doesn't show pls open the page's dev tool (F12), refresh it to see if there's any error message (red lines). Help us by posting a screenshot as well. Tks,

Suma Gowda commented on May 11

I tried with above code also. Still showing same.

Showing exception in Inspect Page:

Uncaught ReferenceError: KoolReport is not defined

at (index):79:1

(anonymous) @ (index):79 (index):85 Uncaught ReferenceError: KoolReport is not defined

at (index):85:5

Reference line index file:

<script type="text/javascript"> KoolReport.widget.init({"js":["\/KoolReport\/get__start\/vendor\/koolreport\/core\/src\/clients\/jquery\/jquery.min.js",["\/KoolReport\/get__start\/vendor\/koolreport\/core\/src\/widgets\/koolphp\/table\/table.js"]],"css":["\/KoolReport\/get__start\/vendor\/koolreport\/core\/src\/widgets\/koolphp\/table\/table.css"]},function(){

ktable627b92b8ba22c1 = new KoolReport.koolphp.table('ktable627b92b8ba22c1',{"cKeys":["customerName","SaleAmount"],"removeDuplicate":[],"paging":null});
    });

</script>

Sebastian Morales commented on May 12

Pls open your page's dev tool (F12), go to tab Network and find file KoolReport.js to see if it's loaded. If it's has an error loading (red line), right click to see its url path and open it in another tab to see if its can be loaded. Let us know the result. Tks,

Suma Gowda commented on May 12

thank you. No js files are loaded in network area. Only path access info is showing. Respective Js files are there in Vendor folder.

Suma Gowda commented on May 12

Core package is support for this issue right?

Sebastian Morales commented on May 12

What's the url path for KoolReport.js and what happens when you open that path in a new tab?

Suma Gowda commented on May 12

No JS files is loading in a page loading.

Sebastian Morales commented on May 12

Pls open your page with dev tool's network opened, refresh the page and show us the screenshot.

Suma Gowda commented on May 13

Yeah. issue is Fixed Now. Issue with the folder structure. Now Js files are loaded. Thanks for valuable time with me.

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
bug
help needed
solved

None