First point -- nothing much to do with chemistry! This is physics.
Not easy to explain simply... Light is a wave, and two waves overlapping interfere. A diffraction grating makes the light pass through thousands of very narrow slits, of a simlar spacing to the wavelength of the light.
As the light passes through each slit, it fans out and overlaps with the light going through the other slits. As the different waves interfere, some are cancelled out, making dark zones.
If the light was of mixed wavelengths to start with (for example, white light), the dark zones for each are in different places for each colour (wavelength). This means the grating splits white light into a spectrum.
Have a look at this page (pretend not to notice the formulae though):
http://explanation-guide.info/meaning/Diffraction.html The top picture shows quite well what happens with one wavelength and two slits.