cowboy me, 2.0: jose nazario beauty and the street


google charts, python





i'm not usually one to fawn over google stuff, but the chart API was useful to me. i rolled it into some code that i wrote, and using that i generated the above pie graph. i did the whole thing in python, and so i translated the "simpleEncode()" routine into python.
def simpleEncode(values,maxValue):
    # values is a python list of numbers
    # based on simpleEncode(values,maxValue) from
    # http://code.google.com/apis/chart/
    simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
    chartData = ['s:']
    for i in values:
        if str(i).isdigit() and i >= 0:
            chartData.append(simpleEncoding[(len(simpleEncoding)-1) * i/maxValue ])
        else:
            chartData.append('_')
    return ''.join(chartData)
note that the if str(i).isdigit() bit isn't needed you pass in a list of numbers, and in JScript you have typing done less strictly, hence the need to ensure it's a number. this should work for any of the chart types - bar, pie, line, etc ... just change the other URL parameters. i would also probably cut back on the long variable names.

the chart above is of a queue counts by priority.

see http://code.google.com/apis/chart/.

|

----

next Sunday, Feb 03, 2008 @ 03:56pm | previous Saturday, Aug 11, 2007 @ 06:48pm | archives

Last modified: Sunday, Dec 09, 2007 @ 08:00am
Weblog Commenting and Trackback by HaloScan.com

Your Ad Here

copyright © 2002-2014 jose nazario, all rights reserved.