Possible solutions:
scrollbar for the legend (not very elegant but simple & quick)
display the first N followed by a "<X> more" button that displays a popover with the rest