起始时间序列高位图在特定日期/时间绘制
Starting Time Series Highcharts Plot at specific date/time
我刚开始使用Highcharts JS库,在特定日期和时间启动图表时遇到了一些问题。该图表是一个流量仪表图表,因此我的X值是日期/时间(EPOCH格式),y值是仪表高度。
我希望我的图表涵盖从午夜开始的3天,即今天日期前2天。我试图使用"pointStart"来建立图表x值的开头,但它不太起作用。我得到了我的三天时间跨度,但起点不是理想的午夜。
我做错了什么?这是我的全高图代码:
$(function () {
$('#gChart').highcharts({
chart: {
type: 'spline',
margin: [20,40,50,60]
},
legend: {
enabled: false
},
title: {
text: null
},
xAxis: {
title: {
text: 'Date',
style: {
color: 'black',
fontWeight: 'bold'
}
},
type: 'datetime',
gridLineWidth: 1,
lineWidth: 1,
lineColor: 'black',
labels: {
formatter: function () {
var curVal = this.value;
var dt = new Date();
theDate = new Date(eval(eval(curVal + 28800) * 1000));
if (theDate.toString('h tt') == "0 AM") {
var t = theDate.toString('M/d/yyyy');
} else {
var t = theDate.toString('htt');
}
return t;
},
style: {
color: 'black'
}
},
startOnTick: true,
endOnTick: true,
gridLineColor: '#222',
tickInterval: 86400,
minRange: 259200,
minorGridLineColor: 'red',
startOnTick: true,
plotlines: [{
color: 'black',
label: {
text: 'Last Update',
align: 'Right',
style: {
color: 'black',
fontWeight: 'bold',
}
},
value: theData[theData.length-1].x,
width: 1
}]
},
yAxis: {
title: {
text: 'Stage (Ft)',
style: {
color: 'black',
fontWeight: 'bold'
}
},
lineWidth: 1,
lineColor: 'black',
min: chartProps["lowGraph"],
max: chartProps["highGraph"],
minorGridLineWidth: 0,
gridLineWidth: 1,
alternateGridColor: null,
startOnTick: true,
plotLines: [{ // Flood Stage 2
value: chartProps["floodPhase2"],
dashStyle: 'Dash',
color: '#FFDC14', //Yellow
width: '4',
label: {
text: 'FLOOD STAGE 2',
align: 'center',
style: {
color: '#FFDC14', //Yelow
fontWeight: 'bold',
fontSize: '10pt'
}
}
}, { // Flood Stage 3
value: chartProps["floodPhase3"],
dashStyle: 'Dash',
color: '#FFA500',
width: '4',
label: {
text: 'FLOOD STAGE 3',
align: 'center',
style: {
color: '#FFA500',
fontWeight: 'bold',
fontSize: '10pt'
}
}
}, { // Flood Stage 4
value: chartProps["floodPhase4"],
dashStyle: 'Dash',
color: 'red',
width: '4',
label: {
text: 'FLOOD STAGE 4',
align: 'center',
style: {
color: 'red',
fontWeight: 'bold',
fontSize: '10pt'
}
}
}]
},
tooltip: {
valueSuffix: ' ft',
formatter: function() {
var curVal = this.x;
var dt = new Date();
theDate = new Date(eval(eval(curVal + 28800) * 1000));
var d = theDate.toString('M/d/yyyy');
if (theDate.toString('h') == "0") {
var t = "12:" + theDate.toString('mm tt');
} else {
var t = theDate.toString('h:mm tt');
}
theString = d + ' @ ' + t + '<br><b>Gage Height: ' + this.y + ' Ft</b>';
return theString;
}
},
plotOptions: {
spline: {
lineWidth: 2,
states: {
hover: {
lineWidth: 2
}
},
marker: {
enabled: false
},
pointInterval: 900, // 5 minutes
pointStart: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()-2,0,0,0,0)
}
},
series: [{
name: 'Gage Height',
data: theData
}]
,
navigation: {
menuItemStyle: {
fontSize: '10px'
}
}
});
});
事实证明,我有很多事情发生,这些事情阻止了图表以我想要的方式出现。首先,当您为图表的轴指定dateTime类型时,Highcharts假设日期信息为毫秒Epoch格式。我的数据是秒格式,所以这是我需要纠正的一件事。
第二个问题是,我的数据来源忽略了夏令时(因此忽略了小时轮班)。一旦我解释了这两个问题,我的图表的轴终于出现了。
相关文章:
- D3在一个调用中绘制不同的SVG形状,没有可见性
- 比较从函数和生成的日期对象
- Json数据包含日期和时间格式
- Javascript日期格式类似于ISO,但本地
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 如何在JavaScript中延长当前日期
- 有没有一个javascript图形绘制库可以进行气球树布局
- 两位数的月份日期验证
- 使用谷歌图表在x轴上绘制日期
- 浮点:以日期/时间作为 x 轴的图形未正确绘制
- 用谷歌图表json数据绘制简单的折线图,日期在x轴上
- Highchart:从 java 传递系列映射时绘制日期时间图表问题
- .js当前时间线:如何仅根据日期绘制线条
- 起始时间序列高位图在特定日期/时间绘制
- 在x轴折线图上绘制错误日期的高位图表(高位股票)
- D3不能在safari中绘制日期轴,解析错误
- 为elasticsearch日期直方图绘制一个空间隔
- 如何动态设置日期范围变量并重新绘制谷歌图表
- 如何在Chart.js中绘制日期
- Highcharts未将日期字符串绘制为类别