Abstract: The representation of the resolvent as an integral operator, the m function, and the associated spectral representation are fundamental topics in the spectral theory of self-adjoint ordinary differential operators. Versions of these are developed here for canonical systems Ju'=-zHu of arbitrary order. A classical result shows that canonical systems of order two can be used to realize arbitrary spectral data, in the form of m functions from the upper half plane to itself. In this paper, canonical systems on graphs, not necessarily compact but with finitely many vertices, are introduced and proved to be unitarily equivalent to certain higher order canonical systems. It is shown that any Schr¨odinger operator on a graph is unitarily equivalent to a canonical system on the same graph. Consequently, for an arbitrary canonical system or Schr¨odinger operator on a graph, a representation of the resolvent as an integral operator and a spectral representation are obtained.