Reputation: 6149
I'm using highcharts time series, I need to add another data series populated from a different json file/link, is that possible?
Here is my code:
$(function () {
$.getJSON('myfirstjson', function (data) {
mydata = [];
$('#tvmtgm').highcharts({
chart: {
zoomType: 'x'
},
title: {
text: 'TVM/TGM'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats : {
hour: '%I %p',
minute: '%I:%M %p'
}
},
yAxis: {
title: {
text: 'Moves'
}
},
legend: {
enabled: false
},
plotOptions: {
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, Highcharts.getOptions().colors[0]],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
]
},
marker: {
radius: 2
},
lineWidth: 1,
states: {
hover: {
lineWidth: 1
}
},
threshold: null
}
},
series: [{
type: 'area',
name: 'Total vessel moves',
data: data
}
]
});
});
});
There are examples on the highcharts website, but they are all static data series, I need to have both data series populated from json requests
Upvotes: 0
Views: 136
Reputation: 96
Yes you can. Of course, I am hoping I understood your problem.
This link shows you how you can add multiple y-axes.
As for getting the data. $.when
should help you.
var data1, data2;
$.when(
$.getJSON(onurl1, function(data) {
data1 = data;
}),
$.getJSON(onurl2, function(data) {
data2= data;
})
).then(function() {
//use data1 and data2
});
Upvotes: 2