我正在使用highcharts time series ,我需要添加另一个由不同 json 文件/链接填充的数据系列,这可能吗?
这是我的代码:
$(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
}
]
});
});
});
highcharts网站上有示例,但它们都是静态数据系列,我需要从json请求填充这两个数据系列
最佳答案
是的,你可以。当然,我希望我理解你的问题。
This link向您展示如何添加多个 y 轴。
至于获取数据。 $.when
应该对你有帮助。
var data1, data2;
$.when(
$.getJSON(onurl1, function(data) {
data1 = data;
}),
$.getJSON(onurl2, function(data) {
data2= data;
})
).then(function() {
//use data1 and data2
});
关于javascript - 在一个highchart中添加两个json数据系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35201089/