513 chart fixes

Closes #513, and possible also fixes #651, though not sure about that one.
Also adds numerous tests to the charts.
Finally, added a function called counts->lengths that is tested, but not yet used; it will soon be needed for the mapview.