# 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 (  => Array ( [expense_category] => Entertainment [sum(amount)] => 1190 )  => 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[field]);

``````

for retrieve data than findAll because you can’t use all rows conveniently
{"ft_lang_label":"__label__en","ft_lang_prob":0.579224,"math_prob":0.6661934,"size":3452,"snap":"2023-14-2023-23","text_gpt3_token_len":937,"char_repetition_ratio":0.14820185,"word_repetition_ratio":0.24434389,"special_character_ratio":0.32589802,"punctuation_ratio":0.16083916,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96507466,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-21T04:59:05Z\",\"WARC-Record-ID\":\"<urn:uuid:b275d9d6-7ba5-4252-9836-e2b807472790>\",\"Content-Length\":\"28998\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a771f710-6eeb-40f9-b0da-82bbd2409b15>\",\"WARC-Concurrent-To\":\"<urn:uuid:6ce0b373-f75e-4914-b47a-b7523cbb1278>\",\"WARC-IP-Address\":\"159.69.125.49\",\"WARC-Target-URI\":\"https://forum.yiiframework.com/t/providing-query-data-to-highchart/44147\",\"WARC-Payload-Digest\":\"sha1:U2EDDWUJQ5WJ34GDLZ6BBWZDAWILWXSU\",\"WARC-Block-Digest\":\"sha1:FD7UB5ITPGDFS6SY4XVZTDCLZ6FBLPXT\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296943625.81_warc_CC-MAIN-20230321033306-20230321063306-00105.warc.gz\"}"}