Creating Pcharts in Cake 3

Im having message error when trying to view my chart

Warning (2): array_push() expects parameter 1 to be array, null given [APP/Template\Fusioncharts\index.ctp, line 31]

Here is the index.ctp

<?php
use Cake\Core\App;
//including the FusionCharts PHP wrapper
require_once(ROOT .DS. 'vendor' . DS  . 'fusioncharts' . DS . 'fusioncharts.php');
use Cake\ORM\TableRegistry;
//connecting to the database table
$chartData = TableRegistry::get('mscombi2ddata');
//query to fetch the desired data
$query = $chartData->find();
//creating the array contains chart attribute
$arrData = array(
        "chart" => array(
         "animation"=>"0",
        "caption"=> "Albertsons SuperMart",
        "subCaption"=> "No. Of Visitors Last Week",
        "xAxisName"=> "Day",
        "yAxisName"=> "No. Of Visitors",
        "showValues"=> "0",
        "paletteColors"=> "#81BB76", 
        "showHoverEffect"=> "1",
        "use3DLighting"=> "0",
        "showaxislines"=> "1",
        "baseFontSize"=> "13",
        "theme"=> "fint"
        )
   );
     foreach($query as $row) {
     $value = $row["value1"];
     array_push($data, array(
          "label" => $row["category"],
          "value" => $row["value1"]
                   )
              );
          }

  $arrData["data"]=$data;

//encoding the dataset object in json format
  $jsonEncodedData = json_encode($arrData);

// chart object
$columnChart = new FusionCharts("column2d", "chart-1", "100%", "300", "chart-container", 
"json", $jsonEncodedData);

 // Render the chart
  $columnChart->render();
?>
// Container to render the chart
 <div id="chart-container"></div>

Fixed Change :

<?php
use Cake\Core\App;

//App::uses('fusioncharts/fusioncharts.php', 'Vendor');
 require_once(ROOT .DS. 'vendor' . DS  . 'fusioncharts' . DS . 'fusioncharts.php');

use Cake\ORM\TableRegistry;

 $chartData = TableRegistry::get('mscombi2ddata');

$query = $chartData->find();

  $arrData = array(
    "chart" => array(
        "animation"=>"0",
        "caption"=> "Albertsons SuperMart",
        "subCaption"=> "No. Of Visitors Last Week",
        "xAxisName"=> "Day",
        "yAxisName"=> "No. Of Visitors",
        "showValues"=> "0",
        "paletteColors"=> "#81BB76", 
        "showHoverEffect"=> "1",
        "use3DLighting"=> "0",
        "showaxislines"=> "1",
        "baseFontSize"=> "13",
        "theme"=> "fint"
        )
        );
        // creating array for categories object

        
        $data=array();


      // pushing category array values
        foreach($query as $row) {

            $value = $row["value1"];
            
            array_push($data, array(
            "label" => $row["category"],
            "value" => $row["value1"]
                   )
              );

          }

  $arrData["data"]=$data;

  $jsonEncodedData = json_encode($arrData);

  $columnChart = new FusionCharts("column2d", "chart-1", "600", "300", "chart-container", 
 "json", $jsonEncodedData);

        // Render the chart
        $columnChart->render();
   // closing db connection
  ?>

<div id="chart-container"></div>

Just slap $data = array(); somewhere before the foreach() and you should be good.

EDIT: you apparently already figured out yourself :slight_smile: