513 chart fixes

Closes #513 and possibly closes #651
Also added many tests for numerical + date charts.
Also added a (tested!) function counts->lengths that is not yet used, but predicting usage for the view-by legend.