Energy Stored in Spring 

Area Z represents the energy stored in the spring when it is stretched to a length L

I am trying to understand why this is so:
$$E = \frac{1}{2}kx^2$$
Here, $x$ is the vertical side of triangle $Y$. This way, $E = \frac{1}{2}x^2 = Area \ Y $  if and only if the slope of the line is $1$. What I am struggling to understand (or visualise to get an intuitive understanding) is how the factor $k$ compensates for this extra area when the slope does $not$ equal 1.
Any help will be greatly appreciated, thanks in advance. 
 A: Precisely, the point is that the slope is not equal to 1. The ratio $\dfrac{F}{\Delta L}=k$. Therefore, $Z=\dfrac{1}{2}(x)*(\dfrac{x}{k})$ $= \dfrac{1}{2k}x^2$. Which looks wrong but is true because in the notation you are using, $x$ is not the elongation but is rather the force acting. So in a more familiar notation $E=\dfrac{1}{2k}F^2$. If you want to express the same formula in the terms of the elongation (let's call it $\Delta L = l$) then $E=\dfrac{1}{2k}F^2=\dfrac{1}{2k}(kl)^2 = \dfrac{1}{2}kl^2$.
A: My explanation is as follows
Force on the spring in stretching it to length x can be written as 
$F=k(x-L_0)$
where x is the displacement, $L_0$ is the initial length of the spring and k is spring constant. energy stored is 
$dE=F.dx$
upon integration we will get
$E=\frac{1}{2}.k.(L-L_0)^2$
where $L$ is the final length of the spring. This is I think you already know.
now the length of triangle base in the graph = $W = F=k(L-L_0)$
length of triangle height = $(L-L_0)$
area of tringle = $\frac{1}{2}$.base.height
=$\frac{1}{2}k.(L-L_0)^2$
I think this will answer your query
