# Graphing number of people from two times

Go to solution Solved by Barand,

## Recommended Posts

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 by VrX
##### Share on other sites

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.

##### Share on other sites

• Solution

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
)

)

)
```
##### Share on other sites

Thanks for that much apreciated

##### Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.