Start by hardcoding a complete array of three-letter months. Then create an array with those months as keys with zero values for all.
Then query your database for existing amounts. You are going to want to have a way of isolating year-specific data as the years go by. At the very least, you should be filtering on FormId so that you are not accidentally including unrelated data from the same table. (I'll add 99 in my demonstration.)
After you query, add the new found amounts to your zero amounts for any found months.
After all of the calculations are done, loop through your prepared data to display the months and their totals.
Without listing all of the months, you will only see the months that are present in the database table. This solution will consistently deliver 12 months.
Note: Never show $query->dump() or $e->getMessage() to the public! This is purely to help you diagnose any coding mistakes while developing from my script. Once your script is working, comment the two JFactory::getApplication()->enqueueMessage() lines out.
Tested Code:
$months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
$monthlySums = array_fill_keys($months, 0);
$db = JFactory::getDBO();
$query = $db->getQuery(true)
->select("FieldName, SUM(FieldValue) AS Sum")
->from("#__rsform_submission_values")
->where([
"FormId = 99",
"FieldName IN (" . implode(',', $db->q($months)) . ")"
])
->group("FieldName");
JFactory::getApplication()->enqueueMessage($query->dump(), 'info'); // never show dump() to public
try {
$db->setQuery($query);
$objects = $db->loadObjectList();
foreach ($objects as $object) {
$monthlySums[$object->FieldName] += $object->Sum;
}
} catch (Exception $e) {
JFactory::getApplication()->enqueueMessage("Query Syntax Error: " . $e->getMessage(), 'error'); // never show getMessage() to public
}
foreach ($monthlySums as $month => $sum) {
echo "<div>{$month}: {$sum}</div>";
}