I'm currently working with sugars at the lab. The yellow ones are samples with glucose while the red ones have xylose. Glucose is the most common simple sugar. Our body needs it for energy. Xylose, on the other hand, is the main sugar extracted from wood.
The colors of the samples are a result of a chemical reaction between a colorant and the sugars. The higher the amount of sugars, the darker the color and the sweeter the samples, I imagine.
A machine called a spectrophotometer measures the colors in terms of absorbance and allows me to determine the exact amount of the sugars in the sample. Another way is, of course, to taste it.