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('&');
}
Comments