Created
August 9, 2011 22:52
-
-
Save anonymous/1135410 to your computer and use it in GitHub Desktop.
Draw pie charts
This file contains 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
// Draw pie 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}}); | |
} | |
// 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