There are two histories of the I Ching, the mythological and the academic, and they are both sort of muddled.
Historically the I Ching probably developed out of the earlier methods of tortoise shell and ox shoulder-bone divination, whereby a red-hot poker was applied to the bone or shell and the random pattern of cracks examined by priests who deduced the meaning. In this there is little difference with similar forms of divination from the ancient mediterranean world.
In China however the the patterns of cracks inspired a more systematic approach in terms of geometric lines - i.e. the hexagrams. Exactly how the jump from cracks to hexagrams was made is not explained.
After the hexagrams were deduced the trigrams were later formulated as a simplified and idealised theoretical underpinning (this aspect of the historical approach I believe to be correct)
Mythologically, the authorship of the I Ching, or at least of the eight trigrams, is attributed to China's first emperor, a mythological figure called Fu Hsi (or Fu Xi), also called Pao Hsi, who was supposed to be half man half dragon, and lived about 5000 years ago. One day he saw a dragon-horse rise from the Yellow River. On it's side were markings, which were recorded as the Ho Tu, or Yellow River map. This is shown here in its ancient (left) and modern (right) forms:
Fu Hsi interpreted the four directions and four diagonal directions of the Ho Tu in terms of the so-called Earlier Heaven (symmetrical) arrangement of the 8 trigrams:
About 1000 years later, another mythical emperor, Yu (father of the first emperor of the Chia dynasty) saw a tortoise with similar markings on it's shell, rising from the Lo River. This became the Lo Shu map, shown below:
Yu interpreted the 4 directions and 4 diagonal directions of the Lo Shu in terms of the so-called Later Heaven (asymmetrical) arrangement of the 8 trigrams of the I Ching, and incorporating the four seasons and five elements. It is said that the Earlier Heaven arrangement refers to the archetypal order of things before creation, whereas the Later Heaven arrangement refers to the order of change in the manifest world
Wen Wang (who flourished about 1150 BC) is traditionally thought to have been author of the present hexagrams. He was a powerful feudal lord who incurred the enmity of the last Shang Emporer, Chou Hsin, and was sentenced to death. While languishing in prison he meditated on the trigrams and combined them to form the 64 hexagrams, each of which he named and organised in their present arrangement. He is also said to have written the basic text, thus adding moral counsel to the original divinatory function of the hexagrams.
After a year in prison Wen was released through the influence of his friends. After his death the hexagrams were studied by his son, the Duke of Chou, who added his own commentaries.
Following Chou Hsin's overthrow, Duke of Chou, became ruler and founded the new Chou dynasty, giving his father the posthumous title King Wen. The book they worked on became known as the Chou I - the "Changes of Chou"
In the 5th century Kung Fu-tze (Confucious) studied the Chou I. It is probable that he and his followers added further philosophical commentary,and the work was incorporated into the Confucian cannon as the I Ching - the Book (or Classic) of Changes.