Chaotic dynamics and halo formation in charged-particle beams