Tractor purchase
by E D
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://highcharts.github.io/export-csv/export-csv.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
JavaScript
$(function() {
//settings
var indicator = "AG.AGR.TRAC.NO"; //quid if request fail: vector empty need to fix this
var country1= "VNM";
var country2= "KHM";
var display=60;
var time=60;
// Set up URL request
var url_country1 = "https://api.worldbank.org/v2/countries/" + country1 + "/indicators/" + indicator + "?per_page=" + display + "&MRV=" + time + "&format=json"
var url_country2 = "https://api.worldbank.org/v2/countries/" + country2 + "/indicators/" + indicator + "?per_page=" + display + "&MRV=" + time + "&format=json"
console.log(url_country1)
console.log(url_country2)
var arrayString = [],
Date = [],
array_country1 = [],
array_country2 = [],
arrayString_country1 = [],
arrayString_country2 = []
$.ajax({
url: url_country1,
complete: function(json) {
text = json.responseText
json = JSON.parse(json.responseText);
$.each(json[1], function(i, data) {
country_name1 = data.country.value;
// fill the string data array
arrayString_country1.push(data.value);
//To set date parameter
Date.push(data.date);
});
$.ajax({
url: url_country2,
complete: function(json) {
json = JSON.parse(json.responseText);
$.each(json[1], function(i, data) {
country_name2 = data.country.value;
arrayString_country2.push(data.value);
});
// querry send string that we need to convert into numbers or null
for (var i = 0; i < arrayString_country1.length; i++) { // we use world lenght since the world serie is supposed to be the longer (the one with no missing values)
if (arrayString_country1[i] != null) {
array_country1.push(parseFloat(arrayString_country1[i]))
} else {
array_country1.push(null)
};
if...