Chemical evolution in simulations of galaxy formation