Refactor charts

The chart code was not well separated from the rest of the code base. Plus it had gotten messy and confusing. I'm spending some time refactoring this code into a new Chart class and cleaning things up.