Most of the graphing programs out there that are opensource are using RRDTool written by Tobias Ottiker and then they write a display interface on top of that. I'm not sure why you would want to go and re-invent the wheel though when there's lots of good solutions already out there that you can view their source and see how they work.
Cacti is good, so is Ntop. You'll need hardware that supports SNMP to be able to graph traffic flows. Getting managed hardware is normally out of the price range for your normal home network though.



