VrX Posted February 27, 2016 Share Posted February 27, 2016 (edited) Not 100% sure where to start on this one... Basically I will have a table containing shift start / end time and number of people working e.g. Shift Start | Shift End | Supervisors | Staff 1000 | 2000 | 1 | 5 1200 | 2200 | 1 | 3 etc... (will be other bits such as date but left out as not important atm) What I would then like to do is a simple line / bar graph showing number of workers over a 24 hour period with 0-23 across bottom and then count running across. So with above example for supervisors it will be 0 for 0-9, 1 for 10 & 11, 2 for 12-19, etc... Can anyone think of a simple way of doing this? (also there will be night shifts to make things a bit more akward). EDIT: Forgot to say graphing etc... I can manage, just after a way of returning the raw numbers. Also only see math forum after I posted *doh* sorry for a wrong forum 1st post Edited February 27, 2016 by VrX Quote Link to comment https://forums.phpfreaks.com/topic/300902-graphing-number-of-people-from-two-times/ Share on other sites More sharing options...
NotionCommotion Posted February 27, 2016 Share Posted February 27, 2016 First, you need to calculate your employees per hour. You can either do this by creating a fancy query, or just retrieving your data as you show it and iterating over it to get the results. Then, I would recommend a JavaScript plugin such as http://www.jqplot.com/examples/barTest.php to create your graph. Quote Link to comment https://forums.phpfreaks.com/topic/300902-graphing-number-of-people-from-two-times/#findComment-1531533 Share on other sites More sharing options...
Solution Barand Posted February 27, 2016 Solution Share Posted February 27, 2016 Set up the array structure that you need for your chart data then process your input, accumulating the data for each hour // // INPUT DATA // $input = [ ['0900', '2000', 1, 5], ['1000', '2200', 1, 3] ]; // // PREPARE ARRAYS TO STORE CHART DATA // $init = array_fill_keys(range(0,23), 0); $data = [ 0 => ['name'=>'Supervisors', 'data'=>$init ], 1 => ['name'=>'Staff', 'data'=>$init ] ]; // // PROCESS THE INPUT // foreach ($input as $row) { list($start, $end, $sup, $staff) = $row; for ($hr=$start/100; $hr<$end/100; $hr++) { $data[0]['data'][$hr]+=$sup; $data[1]['data'][$hr]+=$staff; } } // // CHECK CHART DATA // echo '<pre>',print_r($data, true),'</pre>'; result Array ( [0] => Array ( [name] => Supervisors [data] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 1 [10] => 2 [11] => 2 [12] => 2 [13] => 2 [14] => 2 [15] => 2 [16] => 2 [17] => 2 [18] => 2 [19] => 2 [20] => 1 [21] => 1 [22] => 0 [23] => 0 ) ) [1] => Array ( [name] => Staff [data] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 5 [10] => 8 [11] => 8 [12] => 8 [13] => 8 [14] => 8 [15] => 8 [16] => 8 [17] => 8 [18] => 8 [19] => 8 [20] => 3 [21] => 3 [22] => 0 [23] => 0 ) ) ) Quote Link to comment https://forums.phpfreaks.com/topic/300902-graphing-number-of-people-from-two-times/#findComment-1531536 Share on other sites More sharing options...
VrX Posted February 27, 2016 Author Share Posted February 27, 2016 Thanks for that much apreciated Quote Link to comment https://forums.phpfreaks.com/topic/300902-graphing-number-of-people-from-two-times/#findComment-1531537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.