How to Calculate the Gradient of a Graph