Template for graph function