When the energy is given to the eletron by heating it, for example the electron is promoted to a higher energy level. This state is unstable and temporary.
When the electron falls back to a lower level. The energy difference is emitted as a photon of light.
Each color of the spectrum is the result of the electron moving to the one energy level to the lower one.