implements graph function