Check if there's enough data to calculate an average before doing so (this previously resulted in entire charts not showing up. Also refactored some of the JS. Closes #3