Graded layers are widely exploited in semiconductor epitaxy as they typically display lower threading dislocation density with respect to constant-composition layers. However, strain relaxation occurs via a rather complex distribution of misfit dislocations. Here we exploit a suitable computational approach to investigate dislocation distributions minimizing the elastic energy in overcritical constant-composition and graded layers. Predictions are made for SiGe/Si systems, but the methodology, based on the exact (albeit in two dimensions and within linear elasticity theory) solution of the stress field associated with a periodic distribution of defects, is general. Results are critically compared with experiments, when possible, and with a previous mean-field model. A progressive transition from one-dimensional to two-dimensional distributions of defects when continuous linear grading is approached is clearly observed. Interestingly, analysis of the low-energy distribution of dislocations reveals close analogies with typical pile-ups as produced by dislocation multiplication.