Proper legend, with a more javascript approach.

Plotting is now done with line and dots, with less code.