Electric field and potential plots across a pn junction diode
Calculating the electric field from the charge density can be done using the first Maxwell equation:

$$\nabla\cdot \vec E = \frac{\rho}{\epsilon}$$

Where \$\rho\$ is the charge density, and \$\epsilon\$ is the permittivity of the material. In a single dimension, this equation is simply:

$$\begin{align}
\frac{dE}{dx} &amp;= \frac{\rho(x)}{\epsilon} \\
&amp;\Downarrow \\
E(x) &amp;= \frac{1}{\epsilon}\int_{-\infty}^{x} \rho(u)du
\end{align}$$

The potential is defined as:

$$\begin{align}
V &amp;= -\int \vec E \cdot d\vec l \\
&amp;\Downarrow \\
V(x) &amp;= -\int_{-\infty}^{x} E(u)du
\end{align}$$

So the integral of a constant charge density results in a linear electric field dependency.

Integrating the linear electric field, results in a quadratic potential.