Loading data from server side file into a java variable for plotting
I want to load data for Chart.js for plotting. My data is created in a directory on the server side.
Name of my file = myFile.json. Based on my trials and the documentation I read, the following works for me pretty well.
<script>
var myData;
$.get("myFile.json", function(data){
alert(data);
myData = data;
});
// ---- This didn't work for same asynchronous reasons ---
alert(myData);
//Send the data to chart.js
var pieData = eval("[" + myData + "']");
// Command to draw the chart onto screen.
</script>
I know that, the $.get method is getting asynchronously, so pieData doesn't plot right. So,
1. How do I make sure data is loaded and only then it is copied to pieData? and plotting takes place later. Thanks in advance, please give a simple example if possible.