In this display the work done is plotted two ways. The red line is the value based on the exact solution to the differential equation describing the spring. The trail of the blue x marks the value based on adding up the areas of the little force by displacement rectangles. As you can see there is good agreement between the results. In fact by taking more displacement slices we can make the difference as small as we like.