The spectrum in the above figure is continuous in frequency, but it is not always the case. The spectrum from a star could have absorption or emission lines. It is because when atoms are in low pressure, they can only emit or absorb light of certain wavelengths. If some EM wave with continuum spectrum passes through some low pressure atoms (e.g. the outer atmosphere of a star), those atoms will absorb the light it likes and creates an absorption line. Similarly, if some low pressure atoms emit EM wave, they will create emission lines. Different elements will have diffeerent sets of lines. By carefully analyzing the spectrum of a star, we can tell which elements the star's surface may contain.