When is the graph of a function a dense set?

Let $f: \mathbb R \to \mathbb R$ be any function. When is the graph of $f$ dense in $\mathbb R^2$?
The only examples I know for this are for non-measurable functions, but is that a necessary condition?

• of course not, e.g. the graph of a function which is non-zero on the rationals may have a dense graph. – Pietro Majer Sep 28 '12 at 11:24
• See also mathoverflow.net/a/90201/75082 lol – ParaH2 Aug 20 '15 at 23:59

For each $q\in\mathbb Q$ choose a sequence $x_{q,n}\to q$ $(n\to\infty)$ such that all $x_{q,n}$ are pairwise distinct. For $\mathbb Q=\lbrace r_n:n\in\mathbb N\rbrace$ define $f(x_{q,n})=r_n$ and $f(x)=0$ for $x\notin \lbrace x_{q,n}: q\in\mathbb Q, n\in\mathbb N\rbrace.$ Then $f$ is measurable and its graph is dense.
However this class of function suggests a solution to your problem, for example $f(a+ \sqrt{2} b ) = a - \sqrt{2} b$ whenever $a,b \in \mathbb{Q}$ and $f \equiv 0$ out of $\mathbb{Q} ( \sqrt{2} )$. In this way you have a measurable function (because it is $0$ out of a countable set) and it has the property of the dense graph.