Is it possible to set max width of a legend?

when there are not too many entries horizontal legend works good, but when there’re 30+ - legend area takes about 50% of the whole container which I want to fix. Is there any solution?

my bad, it’s height, not width