Skip to content

Instantly share code, notes, and snippets.

@ivangonekrazy
Forked from anonymous/gist:1135410
Created August 9, 2011 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivangonekrazy/1135416 to your computer and use it in GitHub Desktop.
Save ivangonekrazy/1135416 to your computer and use it in GitHub Desktop.
Draw pie charts
// Draw pie charts
var charts = [];
function createPie(statsjson, type, div, title) {
if(document.getElementById(div)){
data = createDataArray(statsjson, type, title, 'reg');
if(data.getNumberOfRows() > maxResults){
data.removeRows(maxResults, 999999)
}
var chart = new google.visualization.PieChart( document.getElementById(div) ) ;
chart.draw(data, {width: '100%', height: 300, is3D: true, backgroundColor: 'transparent', title: title, legendTextStyle: {fontSize: 10}});
}
charts.push(chart);
// Add our selection handler.
google.visualization.events.addListener(chart, 'select', function() {
var selection = chart.getSelection();
var message = '';
for (var i = 0; i < selection.length; i++) {
var item = selection[i];
if (item.row != null && item.column != null) {
var str = data.getFormattedValue(item.row, item.column);
message += '{row:' + item.row + ',column:' + item.column + '} = ' + str + '\n';
} else if (item.row != null) {
var str = data.getFormattedValue(item.row, 0);
message += '{row:' + item.row + ', column:none}; value (col 0) = ' + str + '\n';
} else if (item.column != null) {
var str = data.getFormattedValue(0, item.column);
message += '{row:none, column:' + item.column + '}; value (row 0) = ' + str + '\n';
}
}
if (message == '') {
message = 'nothing';
}
console.log('You selected ' + message);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment