MakeChart

This script takes a list of (x,y) coordinates and generates an HTML bar chart.

By Ryan McGreal

Posted April 20, 2010 in Projects (Last Updated April 27, 2010)

Check out the Github repository for source and documentation.

Here's an example use, assuming you save makechart.py somewhere in your PATH:

try: import json
except: import simplejson as json
import urllib
import makechart

# chart with world petroleum production data by month from EIA
url = 'http://quandyfactory.com/json/makechart' 
output = urllib.urlopen(url)
contents = output.read()

dataset = json.loads(contents)
caption = 'World Oil Production by Month, 2001-2010
(Source: EIA)' unit = 'mbpd' chart = makechart.make_chart(dataset, caption, unit) html = makechart.make_html(chart) file = open('makechart_example.html', 'w') file.write(html) file.close

Note: for the sake of convenience, this example uses a sample dataset in JSON format that is hosted on this website.