【发布时间】:2020-01-17 18:26:50
【问题描述】:
我对 Highcharts 还很陌生,使用他们网站上提供的示例,一切都很顺利。直到我想在我的情节中添加另外两个系列的数据之前,这是真的:)。
我正在尝试显示一个情节,其中有来自特定气象站的一些气象数据的时间序列,除此之外,如果我能显示有关气象站何时发生变化的信息会很好,即变化电台的接收器和天线。
如果只更换一次接收器和/或更换一次天线,一切都很好,但是,如下例所示,xAxis 停止显示正常日期,并且通过检查代码它只会呈现一个刻度在 2025.0 这是不正确的,因为该时间段内没有数据。
(function ($) {
$(function () {
Highcharts.dateFormats = {
DOY: function (timestamp) {
var date = new Date(timestamp);
var d= new Date(date.getFullYear(), 0, 0);
return ('00' + Math.floor((date-d)/8.64e+7)).slice(-3);
},
DEC: function (timestamp) {
var date = new Date(timestamp);
return ((1970 + date/(365*8.64e+7)).toFixed(1))
},
WEEK: function (timestamp) {
var date = new Date(timestamp);
var dgps = new Date(1980,0,6,0,0,0);
return Math.floor((date-dgps)/(7*8.64e+7));
}
};
// Meteo chart
Highcharts.chart('plot', {
chart: {
renderTo: 'plot',
zoomType: 'x',
panning: true,
panKey: 'shift',
borderWidth: 1,
borderColor: 'grey',
style: {
fontFamily: 'arial'
},
height: 464
},
title: {
text: 'DEM3',
align: 'left',
x: 10
},
legend: {
enabled: true,
layout: 'horizontal',
align: 'right',
verticalAlign: 'top',
width: 300,
itemWidth: 190,
top:70
},
boost: {
useGPUTranslations: true,
usePreAllocated: true
},
xAxis:
{ type: 'datetime',
title: {
enabled: true,
text: 'Year',
style: {
color: '#c0aa7d',
fontWeight: 'bold',
fontSize: '12px'
}
},
labels: {
format: '{value: %DEC}'
},
lineWidth: 1,
lineColor: '#c0aa7d',
min: 1567023200000,
max: 1578787200000,
},
yAxis:[
{
title: {
text: 'Zenith Total Delay (m)',
style: {
color: '#c0aa7d',
fontWeight: 'bold',
fontSize: '12px'
}
},
lineWidth:0.5,
top: 100,
startOnTick: false,
endOnTick: false,
tickInterval: 0.05,
minorTickInterval: 0.05,
minorTickLength: 0,
min: 2.0687167703582,
max: 2.492349020252,
}],
plotOptions: {
series: {
lineWidth: 0,
marker: {
radius: 2,
symbol: 'circle'
},
turboThreshold: 10000
}
},
series: [ {
id: 'Antenna0',
name: 'Antenna Change',
type:'line',
color: '#35a62a',
dashStyle: 'Solid',
data: [
[1574035200000,2.068716770358151],
[1574035200000,2.4923490202520044]
],
yAxis: 0,
lineWidth: 2,
enableMouseTracking: false,
marker: {
radius: 0
}
}, {
id: 'Receiver0',
name: 'Receiver Change',
type:'line',
color: '#AE0016',
dashStyle: 'longdash',
data:[
[1574035200000, 2.0687167703582],
[1574035200000, 2.492349020252],
[null, null],
[1575158400000, 2.0687167703582],
[1575158400000, 2.492349020252],
[null, null],
[1576713600000, 2.0687167703582],
[1576713600000, 2.492349020252],
],
yAxis: 0,
lineWidth: 1.5,
enableMouseTracking: false,
marker: {
radius: 0
}
},{
type: 'scatter',
name: 'Zenith Total Delay (m)',
color: '#C0B5A9',
marker: {
enabled: true,
symbol: 'circle',
radius: 1.5,
fillColor: '#c0aa7d'
},
data: [
[1567123200000, 2.2877],
[1567209600000, 2.2824],
[1567296000000, 2.266],
...
[1578614400000, 2.2127],
[1578700800000, 2.222],
[1578787200000, 2.2145],
],
yAxis: 0,
}]
});
});
})(jQuery);
示例:https://jsfiddle.net/rgcouto/9qv2ehp7/1/
重现步骤:
1 -按原样打开,绘图将无法正确渲染 xAxis;
2 - 从 Receiver0 系列中移除 second 和 third 事件,只留下 一个 事件[即具有 3 个位置的数组:1 个开始,1 个结束,1 个空(空是删除连接到第二个事件的线)],xAxis 将呈现正常日期。
我整天都在摸不着头脑,但我不知道可能出了什么问题。
提前感谢您的帮助:)
编辑: 通过添加一个额外的隐藏 xAxis 并将其他 2 个系列引用到这个新 xAxis 来解决。
【问题讨论】:
标签: javascript jquery highcharts