generateChart = function(options) { require ( ['https://www.gstatic.com/charts/loader.js'], function() { google.charts.load('current', {'packages':['bar']}); var errorfunction = options.errorCallback; try { var $chartDrawDiv = $(options.divSelector); $chartDrawDiv.addClass('jsChartNoOverflow'); var height = options.dataset.chart_information.height; var width = options.dataset.chart_information.width; var processedData = processData(options.dataset.data); google.charts.setOnLoadCallback(doDrawing(processedData, $chartDrawDiv, height, width)); } catch(err) { errorfunction(err); } } ); }, processData = function(dataset) { var ds = [['Sexo', 'Doações']]; for (var i = 0; i < dataset.sexo.length; i++) { ds.push ([ dataset.sexo[i].formatted_data, dataset.doacoes[i].raw_data ]); } return google.visualization.arrayToDataTable(ds); }, doDrawing = function(data, $chartDiv, height, width, errorFunction) { var chart = new google.charts.Bar($chartDiv[0]); var options = { 'height': height, 'width': width, 'colors': 'steelblue', 'legend': 'left' }; chart.draw(data, options); };