Can any graph be represented by a formula? I am only in high school but interested in maths. Can any graph be represented by a formula or does the graph have to have certain characteristics like a pattern etc?

If you're asking whether a function has to be given by some sort of algorithm or logic, then the answer is no: A function $f:X \to Y$ is simply a subset of $S_f \subset X\times Y$ such that for each $x\in X$, there exists exactly one point $(x, y)\in S_f$; the point $y$ is denoted by $f(x)$. Note that this assignment is deterministic (though not necessarily computable by a human, algorithm, etc.). 
We can talk about the kinds of functions you describe, though; they're just a smaller subset of the space of all functions. For that, "computable function" is probably the concept you want. If you want to relax the deterministic requirement, then "random variable" is probably what you're looking for, but note that there are quite a few technical details required to define them properly.
