Created
February 21, 2009 17:09
-
-
Save simonw/68098 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateChart(figures) { | |
// figures is an object mapping labels to numbers | |
var cht = 'p'; // Chart type: pie | |
var chs = '460x200'; // Image dimensions | |
var chd = []; // Chart data | |
var chl = []; // Corresponding labels | |
var min = 0; | |
var max = 0; | |
$.each(figures, function(label, value) { | |
chl[chl.length] = label; | |
chd[chd.length] = value; | |
max = Math.max(max, value); | |
}); | |
if (max == 0) { | |
return ''; // Don't attempt to render blank graphs | |
} | |
var chds = '' + min + ',' + max; // Chart data scale | |
chd = 't:' + chd.join(','); | |
chl = chl.join('|'); | |
return 'http://chart.apis.google.com/chart?' + [ | |
'cht=' + cht, | |
'chs=' + chs, | |
'chd=' + chd, | |
'chl=' + chl, | |
'chds=' + chds | |
].join('&'); | |
} | |
/* Usage: | |
var src = generateChart({ | |
"foo": 5, | |
"bar": 3, | |
"baz": 6 | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment