I am making a java script application having an html canvas element. Clicking on canvas triggers a java script event. But the order of execution of function is not as expected
$('#canvas1').on('click',function(e){
get_json_data();
//plot the json data
show_curve();
});
function get_json_data(){
$.getJSON("program/heatmap_slices.json",function(data){
console.log("function1");
visibilty = data['photo'][1][1];
});
return ;
}
function show_curve(){
$("#canvas2").show();
console.log("function2");
var canvas2 = document.getElementById('canvas2');
var ctx2 = canvas2.getContext("2d");
var myNewChart = new Chart(ctx2);
var data = {
labels: points,
datasets: [
{
label: "My First dataset",
fillColor: "rgba(175,175,220,0.5)",
strokeColor: "rgba(150,150,220,1)",
highlightFill: "rgba(100,100,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: visibilty,
}
]
};
var options = {
barStrokeWidth : 2,
}
var myBarChart = new Chart(ctx2).Bar(data,options);
points =[];
return;
}
I expect the order of console log should be "function1 followed by function2" but its the other way round. Also if I remove $getJSON method, the execution order comes as expected.