A grainy chocolate ganache happens when the chocolate was not melted all the way or the heavy cream was too hot and caused the chocolate to seize up. To avoid this make sure to start out with finely chopped chocolate and properly heated cream. The cream should just be heated to a low simmer but not be brought to a boil.