Add legend to charts

The draw method is called quite a lot and these anonymous functions will be created every time draw is called (for every chart and every legend), which can be quite a lot if someone is dragging a line chart.

I had some memory problems on the first prototype and moving these functions outside a few levels so they're already defined seemed to improve things.

The most memory efficient way is to assign them to the prototype of the object, but you cannot access 'self' in prototypes and 'this' can be different unless you know it will only be called in a certain context, so what I tend to do is treat them as private functions created once for each instance of Legend.