Prove that $D$ is connected if the set $\{(x,f(x)):x\in D\}$,the graph of $f$ is a connected subset of $\Bbb R^2$ Let $D\subset \Bbb R$.Let $f:D\to \Bbb R$ be continuous .

Prove that $D$ is connected if the set $A=\{(x,f(x)):x\in D\}$,the graph of $f$ is a connected subset of $\Bbb R^2$

I don't know how to proceed.
I assumed $D$ to be disconnected and then took  a continuous surjective function $g:D\to \Bbb \{0,1\}$ .
I want to use $g$ to get a continuous surjective function $h:A\to \Bbb \{0,1\}$ which would prove $A$ disconnected and hence a contradiction.
But I am unable to do that.Please help me out.
 A: Hint: Show that if $f$ is continuous, then the map $\phi:A\to D$ given by $\phi(x, f(x)) = x$ is a homeomorphism, and thus preserves connectedness.
A: 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.
