I am using the following snippet of code to return an java array of doubles to another javascript function.
var getCredits = (function() {
console.log('Getting credits');
$.ajax({
type : 'GET',
url : rootURL+"/getCredits",
dataType : "json", // data type of response
success : function(data){
var array = [];
console.log('Credits data = '+data);
for(var x in data){
console.log('x = '+data[x]);
array.push(data[x]);
}
console.log('credits array is '+array);
return array;
}
});
});
var getDebits = (function() {
var myArray = [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8];
console.log('debits array is '+myArray);
return myArray;
});
when i run the code - logs are the following -
"generating my graph" myMain.js:110 "Getting credits" myMain.js:149 "debits array is 3.9,4.2,5.7,8.5,11.9,15.2,17,16.6,14.2,10.3,6.6,4.8" myMain.js:169 "Credits data = 10.7,20.5" myMain.js:156 "x = 10.7" myMain.js:158 "x = 20.5" myMain.js:158 "credits array is 10.7,20.5"
the getDebits functionality is essentially what i want from the getCredits function. from the logs it looks like its what i want - but i am passing it into another function which looks like -
var generateMyGraph = (function() {
console.log("generating my graph");
$('#myLineGraph').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Finances per month'
},
subtitle: {
text: 'Credit and Debit per month'
},
xAxis: {
categories: ['Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug','Sep','Oct']
},
yAxis: {
title: {
text: 'Euro (€)'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [{
name: 'Credit',
data: getCredits()
}, {
name: 'Debit',
data: getDebits()
}]
});
});
and its not working, any ideas? thanks in advance!