They shake when that pokemon is close to levelling up - I think it's when you have around 1/8 left on the EXP bar.
The six balls in order correspond to your party pokemon left-to-right, top-to-bottom if you didn't know. (Although if you switch pokemon the ordering switches too. The current battling pokemon is always #1.)