This way my histogram works fine,when I load it like during page load.
$(document).ready()
{
x = new Array(10);
for (var i = 0; i < 10; i++) {
x[i] = new Array(2);
x[i][0]="txt";
x[i][1]=100;
}
loadChart2(x);
}
Google column chart code: (adopted from Google charting api)
function loadChart2 (histValues)
{
console.log('histValues:'+histValues);
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(histValues);
var options = {
hAxis: {title: 'Score', titleTextStyle: {color: 'red'}}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
};
My problem:
But when I call loadChart2() from inside my angularJS controller, entire screen becomes white and no error is shown in browser console.
$http({method: 'GET', url: urlGetHistogramData, timeout: maxTime})
.success(function (data) {
x=new Array(data.score_hist.length);
var i=0;
$.each(data.score_hist, function(){
x[i] = new Array(2);
x[i][0]=this.interval_start;
x[i][1]=this.count;
i++;
});
loadChart2(x);
});
Debugging info:
I can see in console that interval_start
and count
values are printed, so service is returning values fine
Also, I can see histValues
expectantly printed on console from loadChart() function.
Here is a related question, in case you want more in-depth details How to create a historgram from json
As soon as I put loadChart2()
function in any AngularJS onClick or any function, I get total white screen with no error in console. It seems, none has any comment on my problem, I will keep this page updated with my findings on this.
Edit I am pursuing a solution to this problem, I asked a question related to this issue https://stackoverflow.com/questions/16816782/how-set-charts-data-in-google-chart-tool-directive-module-from-a-dynamically-po