providing query data to Highchart

hello everyone

I am having trouble with providing data for pie chart in highchart

I am doing following query


$catexp = Yii::app()->db->createCommand()

		->select('expense_category, sum(amount)')

		->from('expense')

		->where('uid=:id', array(':id'=>Yii::app()->user->id))

		->group('expense_category')

		->queryAll();

after priting the result using print_r($catexp); function i am getting the following result


Array ( [0] => Array ( [expense_category] => Entertainment [sum(amount)] => 1190 ) [1] => Array ( [expense_category] => Transportation [sum(amount)] => 1000 ) )

Now my question is how to supply this array data to highchart extension, here is the sample for piechart


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

   'options'=>array(

   'credits' => array('enabled' => false),

   //'theme' => 'grid',

      'title' => array('text' => 'Category Wise Expense'),

      'xAxis' => array(

         'categories' => array('Apples', 'Bananas', 'Oranges')

      ),

      'yAxis' => array(

         'title' => array('text' => 'Fruit eaten')

      ),

      'series' => array(

    array('type' => 'pie',

          'name' => 'Pie Chart', 

          'data' => <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?? //how to supply $catexp array here

         

	))

   )

));

Hello! it seems nobody is familiar with highchart extension anyways after so much struggle i found out that we can supply query result directly to highchart data like this


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

   'options'=>array(

   'credits' => array('enabled' => false),

   //'theme' => 'grid',

      'title' => array('text' => 'Category Wise Expense'),

      'xAxis' => array(

         'categories' => array('Apples', 'Bananas', 'Oranges')

      ),

      'yAxis' => array(

         'title' => array('text' => 'Fruit eaten')

      ),

      'series' => array(

    array('type' => 'pie',

          'name' => 'Pie Chart', 

          'data' => $catexp,

         

        ))

   )

));

before this you need to change your query such that it gives % for the value you want to supply. I am using like this


$catexp = Yii::app()->db->createCommand()

		->select('expense_category as "name", round(sum(amount)*100/'.  $totexp->expsum .') as "y"')

		->from('expense')

		->where('uid=:id', array(':id'=>Yii::app()->user->id))

		->group('expense_category')

		->queryAll();



But after all this I am getting result which is little incorrect and i dont undrstand till now why i am getting this output - see attachment

I am supplying the correct values in form of % but piechart is showing it in diff form2146

Capture.JPG

did you find a solution

this is my code


$datas =  Status::model()->findAll(array('select'=>'id',

'order'=>'id', 'condition'=>'id!=:x', 'params'=>array(':x'=>0)));

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

   'options'=>array(

        'title' => array('text' => 'Fruit Consumption'),

        'xAxis' => array(

        'categories' => array('Apples', 'Bananas', 'Oranges', 'Apples1', 'Bananas1', 'Oranges1', 'Bananas2')

        ),

        'yAxis' => array(

        'title' => array('text' => 'Fruit eaten')

        ),

        'series' => array(

        array('name' => 'Jane', 'data' => $datas)

        )

   )

));

I think that is imposible if you try provide data with Yii to this extension, maybe is better to forget about it and work with php with bared hands work with arrays and strings to make this possible.

and i think that is better if you use


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

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

$rows=$command->queryAll();

echo($rows[0][field]);

for retrieve data than findAll because you can’t use all rows conveniently