I Can't Create Static Pie Chart Into Dynamically

below static code was working perfectly ,


$this->widget('ext.highcharts.HighchartsWidget',array(

        'options' => array(

                'series' => array(array(

                        'type' => 'pie',

                       'data' => 

						array(

						//$test_chart

                                array('Firefox', 44.2),

                                array('IE7', 26.6),

                                array('IE6', 20),

                                array('Chrome', 3.1),

                                array('Other', 5.4)

                        )

                ))

        )

));



then am convert in to this dynamically,

fetch contents into db




<?php

		//$categories_fetch=array();

		$connection=Yii::app()->db;

		$sqlf = "SELECT pos_item_inventory.id as inid,pos_item_inventory.itemid as itemid,pos_item_inventory.total_stock,pos_item.name FROM pos_item_inventory LEFT JOIN pos_item on pos_item.id=pos_item_inventory.itemid";

		$command = $connection->createCommand($sqlf);

		$dataReaderf = $command->queryAll();

                $test=array();

                foreach($dataReaderf as $key=>$val) {


                 $test[]=array($val['name'],$val['total_stock']);

                 }




print value of $dataReaderf is




Array ( [0] => Array ( [inid] => 1 [itemid] => 1 [total_stock] => 110 [name] => xperia Z ) [1] => Array ( [inid] => 2 [itemid] => 2 [total_stock] => 10 [name] => VIO GT3211 ) [2] => Array ( [inid] => 3 [itemid] => 3 [total_stock] => 19 [name] => IBM Vespo ) ) 






$this->widget('ext.highcharts.HighchartsWidget',array(

        'options' => array(

                'series' => array(array(

                        'type' => 'pie',

                       'data' => $test

						//array(

//						//$test_chart

//                                array('Firefox', 44.2),

//                                array('IE7', 26.6),

//                                array('IE6', 20),

//                                array('Chrome', 3.1),

//                                array('Other', 5.4)

//                        )

                ))

        )

));



then don’t see anything , Please help me!

Hi,

If you assign array directly then it will not work, you have to loop through the $test array, then you form the dynamic string which will have the data similar to this format

$finalstr=‘array(‘Firefox’, 44.2),array(‘IE7’, 26.6),array(‘IE6’, 20),array(‘Chrome’, 3.1),array(‘Other’, 5.4)’;

Try to assign value like this.

thanks for your reply


$finalstr='array('Firefox', 44.2),array('IE7', 26.6),array('IE6', 20),array('Chrome', 3.1),array('Other', 5.4)';






A syntax error occurred after include this code

Try this

$finalstr=“array(‘Firefox’, 44.2),array(‘IE7’, 26.6),array(‘IE6’, 20),array(‘Chrome’, 3.1),array(‘Other’, 5.4)”;

I try this code but graph shown not well please check upload image