Getting database values grouped in an array
SQL query

Of course, all the data calculations should be done on the database side. So the main improvement would be an SQL query like this

select upper(date_format(dateoforder, "%b")), count(1) 
from salessummary group by month(dateoforder);


PDO magic

Next, let's utilize the PDO's magic constant that can load your data into the neat associative array, PDO::FETCH_KEY_PAIR, with month abbreviations as keys and order count for the given month as values

So our code would be

$thisyear =  date("Y");
$sql = "select upper(date_format(dateoforder, "%b")), count(1) 
        from salessummary group by month(dateoforder) WHERE dateoforder LIKE ?";
$stmt = $conn1-&gt;prepare($sql);
$stmt-&gt;execute(array("$thisyear%"));
$data = $stmt-&gt;fetchAll(PDO::FETCH_KEY_PAIR);


Data gathering

It will give us the information for all the data that exists in the database, but with obvious gaps. To fill them, let's run a simple loop

$result = [];
foreach (range(1,12) as $num) {
    $mon = strtoupper(date("M", strtotime("$thisyear-$num-15")));
    $result[$mon] = $data[$mon] ?? 0;
}


and then assemble the final data structure

$datayearly = array(
    'labels' =&gt; array_keys($result),
    'series' =&gt; array(array(
        'name' =&gt; 'series-1',
        'data' =&gt; array_values($result)
    ))
);


Note that the null coalesce operator (i.e. ??) exists in PHP7 only. If your PHP version is outdated, then you could use the old form,

     $result[$mon] = isset($data[$mon]) ? $data[$mon] : 0;