Dynamic value graph creation in yii2 using GoogleChart? -


here wanna draw line chart graph dynamic value.but in case every value of array created different different graph...please me first time task.thanks in advances

<?php  $modelemployee=employee::find()->select(['id','sales','expenses'])->all(); $arr = array('id'=>array(),             'sales'=>array(),             'expenses'=>array()); for($i = 0, $modem = $modelemployee; $i < sizeof($modelemployee); $i++){     $arr['id'] = $modem[$i]['id'];     $arr['sales'] = $modem[$i]['sales'];     $arr['expenses'] = $modem[$i]['expenses']; print_r($arr);     echo googlechart::widget(array('visualization' => 'linechart',                  'data' => array(             array('year', 'sales', 'expenses'),             array($arr['id'],$arr['sales'],$arr['expenses']),      ),                 'options' => array(                     'title' => 'my company performance2',                     'titletextstyle' => array('color' => '#ff0000'),                     'vaxis' => array(                         'title' => 'scott vaxis',                         'gridlines' => array(                             'color' => 'transparent'  //set grid line transparent                         )),                     'haxis' => array('title' => 'scott haixs'),                     'curvetype' => 'function', //smooth curve or not                     'legend' => array('position' => 'bottom'),                 )));  ?>  

enter image description here

first of multiple graphs because doing echo inside loop take 1 value , create graph that.

you have create array of values , pass graph widget following

$graph_data = []; $graph_data[] = array('year', 'sales', 'expenses');   for($i = 0, $modem = $modelemployee; $i < sizeof($modelemployee); $i++){  $arr['id'] = $modem[$i]['id'];  $arr['sales'] = $modem[$i]['sales'];  $arr['expenses'] = $modem[$i]['expenses'];  $graph_data[] = array($arr['id'],$arr['sales'],$arr['expenses']); //add values require set in order of year, sales , expenses } //loop ends here echo googlechart::widget(array('visualization' => 'linechart',              'data' => $graph_data,             'options' => array(                 'title' => 'my company performance2',                 'titletextstyle' => array('color' => '#ff0000'),                 'vaxis' => array(                     'title' => 'scott vaxis',                     'gridlines' => array(                         'color' => 'transparent'  //set grid line transparent                     )),                 'haxis' => array('title' => 'scott haixs'),                 'curvetype' => 'function', //smooth curve or not                 'legend' => array('position' => 'bottom'),             ))); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -