generateChart = function(options) { require(['https://canvasjs.com/assets/script/canvasjs.min.js'], function() { var processedData = processData(options.dataset.data); doDrawing(processedData, $chartDrawDiv, options.dataset.chart_information.height, options.dataset.chart_information.width, options.dataset.attributes.default_colours); }); }, processData = function(dataset) { var ds = [['grade', 'head_count']]; for (var i = 0; i < dataset.grade.length; i++) { ds.push([ dataset.grade[i].formatted_data, parseFloat(dataset.head_count[i].raw_data) ]); } return google.visualization.arrayToDataTable(ds); }, doDrawing = function(data, $chartDrawDiv, height, width, colors) { var chart = new CanvasJS.Chart($chartDrawDiv[0]); var options = { chart:{ title: 'Look I made a chart!', subtitle: 'Have a subtitle' }, height: height, width: width, //colors: 0xff0000, legend: 'left', //bars: 'horizontal' }; chart.render(data, options); }