Let me restate the proper answer.
- Take the
google.load("visualization"...
out of the custom binding code - Avoid calling the
google.setOnLoadCallback(function()...
executing the inner code directly by itself.
Here's how the binding looks now...
google.load("visualization", "1", { packages: ["corechart"] });
ko.bindingHandlers.googleChart = {
init: function (element, valueAccessor, allBindingsAccesor, viewModel, bindingContext) {
//TODO: load & handle visualization data using the 'valueAccessor'
var data = new google.visualization.DataTable();
data.addColumn('string', 'Year');
data.addColumn('number', 'Revenue');
data.addColumn('number', 'Average Revenue');
data.addRows([
['2004', 1000, 630],
['2005', 1170, 630],
['2006', 660, 630],
['2007', 1030, 630]
]);
var options = {
title: 'Revenue by Year',
seriesType: "bars",
series: { 1: { type: "line" } },
vAxis: {
title: 'Year',
titleTextStyle: { color: 'red' }
},
colors: ['red', 'black']
};
var chart = new google.visualization.ComboChart(element);
chart.draw(data, options);
}};
Hope this help any of you working on a similar matter!