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?

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.