If you wanna build your own custom module you can grab code from any one of the following modules and use them in your custom module.
Transform Data into Information. Charts are a very good way to visualize a lot of data in a way that can be quickly digested.
Provides a "charts" style output for Views module so you can render result-set not just as text (list, tabular) but as pie-chart, bar-chart, scatter-plot etc.
Charts and Graphs
Charts and Graphs is an API for developers. It can easily be extended by third-party modules that want to add their own charting implementations. It does nothing by itself. It should only be installed if some other module requires it.