After many hours of labourious testing of the chart query and the code processing that into json data structures and then processing those for use by the flot library, I could confirm that I had an instance of the bug described at https://github.com/flot/flot/issues/1076 and working through that found the solution at
http://www.2general.com/blog/2012/05/30/flot_stacked_bar_chart.html
and the code snippet I needed at https://code.google.com/archive/p/flot/issues/247
I have patched the jquery.flot.stack.js file as instructed there, and the stacking now works properly.