Below is the Code:
Code: Select all
var seriesOptions = []
seriesCounter = 0
names = ['2016', '2017', '2018']
$.each(names, function(i, name){
$.getJSON('http://127.0.0.1:8080/data-' + name,
function(data){
seriesOptions[i] = {
name: name,
data: data
};
seriesCounter += 1;
if ( seriesCounter == names.length )
{
var chart = Highcharts.chart('container2', {
chart: {
type: 'area'
},
title: {
text: 'Monthly Trend for Issued Spare Parts Cost 2016 - 2018'
},
subtitle: {
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
tickmarkPlacement: 'on',
title: {
enabled: false
}
},
yAxis: {
title: {
text: 'Monthly Count Issued Items'
},
labels: {
formatter: function () {
return this.value / 1000;
}
}
},
tooltip: {
split: true,
},
plotOptions: {
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 1,
lineColor: '#666666'
}
}
},
series: seriesOptions
});
}
});
});
$('#button').click(function () {
if (chart.series.length === 1) {
chart.addSeries({
name: '2016',
data: [194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4]
});
}
});[code]