A Data Generation Perspective to the Mechanism of In-Context Learning