scottharwell / GoogleCharts

CakePHP Plugin for Google Charts Javascript API
26 stars 30 forks source link

Support for OrgChart #26

Closed sudipc07 closed 7 years ago

sudipc07 commented 7 years ago

Update to handle 'array' column type. Use case: 'Org Chart Type', with v and f format data. Example data (from the Google Charts page):

          [{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'},
           '', 'The President'],
          [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President</div>'},
           'Mike', 'VP'],
          ['Alice', 'Mike', ''],
          ['Bob', 'Jim', 'Bob Sponge'],
          ['Carol', 'Bob', '']

From Controller, the following code works now:

       $chart->columns(array(
            //Each column key should correspond to a field in your data array
            'name' => array(
                //Tells the chart what type of data this is
                'type' => 'array',     
                //The chart label for this column           
                'label' => 'Name'
            ),
            'manager' => array(
                //Tells the chart what type of data this is
                'type' => 'string',     
                //The chart label for this column           
                'label' => 'Manager'
            )
        ));
         foreach($users as $user){
            //$chart->addRow($user['User']);
            $name = array();
            $name['v'] = $user['User']['name'];
            $name['f'] = $user['User']['name'].'<div class="text-muted text-info">'.$user['Role']['name'].'</div>';

            $chart->addRow( array('name' => $name, 'manager' => $user['Manager']['name']) );
        }