Make generateDynamicQuery function more generic

Increases reusability of this function. Used later to build graphs dynamically.
Allow generation of dynamic graphs

Uses the dynamic queries functions to allow the generation of dynamic graphs.
Addresses #8
Sort generated graphs

Graphs are added to the data array in a ordered manner to ensure the sorting