For the first year, the equation would be 6=24-18, y=6 which is the number of donuts left over and 24 is how many he bought and x=18 which is how many he used. For the second year, the equation is, 2=24-22, y=2 which represents number of donuts left over, 24 represents number of donuts bought, 22 represents number of donuts used.
I can't figure out the graph. Sorry.
I hope this helps!