Any question about influences on Hamlet probably have to start with Ur-Hamlet, a lost play which was written mere decades before William Shakespeare's Hamlet, and has a very similar plot. Other principal sources available to Shakespeare were Saxo Grammaticus’s Historiae Danicae (circa 1200), which features a popular legend with a plot similar to Hamlet, and François de Belleforest’s Histoires Tragiques, which provides an expanded account of the story recorded in the Historiae Danicae.
I influenced Shakespeare to write the play
A lot of people say that it was the death of his son hamnet that lead to a tragedy mainly due to the similarity in names, but there is a gap of 4-5 years between the two events, so no definite basis. Tragedy was the most profitable form and he was good in it and of course the source material was available "the danish story of amneth".