Only render legend when it first needs to be show

Hey @masayuki0812, so we were hitting some performance issues when we had lots of charts on the screen simultaneously. The changes have removed ~13 seconds of rendering time from our charts. :+1: