By your method,
Suppose $D$ is disconnected. Then $\exists$ a continuous and surjective function $g:D \to \{0,1\}.$ So we can write $D=g^{-1}(0) \cup g^{-1}(1)$, where $g^{-1}(0) \cap g^{-1}(1) = \emptyset$ and both are non-empty and closed subsets of $D$. (Note $\{0\}$ as well as $\{1\}$ are closed in $\{0,1\}$).
Observe that $A=\{(x,f(x)) : x \in g^{-1}(0) \cup g^{-1}(1)\}=\{(x,f(x)) : x \in g^{-1}(0)\} \cup \{(x,f(x)) : x \in g^{-1}(1)\}$.
Let $A_1=\{(x,f(x)) : x \in g^{-1}(0)\}$ and $A_2=\{(x,f(x)) : x \in g^{-1}(1)\}$.
Then $A_1 \cap A_2 = \emptyset$ and both $A_1$ and $A_2$ are non-empty.
Take $(y,z)$ to be the limit point of $A_1$. Then there exists a sequence $(y_n,f(y_n))$ in $A_1$ which converges to $(y,z)$. As we established that $g^{-1}(0)$ is a closed subset of $D$, we get $y_n \to y$ in $g^{-1}(0)$.
Continuity of $f$ implies $f(y_n) \to f(y)$. Hence $f(y)=z$ and $(y,z) \in A_1$. That is $A_1$ is a closed subset of $A$. Similarly $A_2$ is also a closed subset of $A$.
Define $h:A \to \{0,1\}$ by $$h((x,f(x))) = \begin{cases} 0, & x \in g^{-1}(0) \\ 1, & x \in g^{-1}(1) \end{cases}.$$
Then $h$ is continuous (because inverse image of closed set is closed) and surjective. Thus giving contradiction on $A$ being connected.