W = Fd is valid only if the force is constant. Can you see that ONLY if the force is constant will the area "under" the graph be given by F*d? That's because this area will be rectangular. If the force varies, then the area will be some other more complicated shape.
In the case of a spring, the restoring force of the spring is NOT constant. It varies depending on how much the spring is compressed. In other words, it varies as a *function* of position. If x is the displacement of the spring from it's equilibrium position, then F = -kx (Hooke's Law). So F is a function of x.
It is possible to derive the formula for the elastic potential energy stored in the spring using integral calculus. If you don't know integral calculus, don't worry about it for now.
Edit: Or in this case, as Doc Al pointed out, the function is simple enough that you can calculate the area without resorting to integral calculus. But what I was trying to get at is that right now you're just calculating the area under the graph because presumably your teacher is telling you that that will give you the amount of work done. Knowledge of integral calculus allows you to understand the most general mathematical definition of work and therefore to understand WHY it is given by the area under the graph.