请帮我在字符串转换成时间format[Hr:Min:Sec]
的Javascript - 转换时间戳到毫秒Highcharts Y轴
这里是我的一块
seriesData_1.push(parseFloat($(this).attr('myVar')));
我试图将此更改为:
seriesData_1.push(Date.parse("1-1-1" + ($(this).attr('myVar'))));
但没有运气。该myVar
将持股价值20:57:13
更新:我在Highcharts & Javascript和使用指导#1哑所以,我得到了我想要的东西。
这是它。我有myVar
系列20:57:13
等Hr:Min:Sec
格式,需要绘制在Y axis
。得知我们在Y轴上有datetime
类型,可以为你绘制图表。但为此,您需要将时间戳转换为毫秒。
这是我为
yourtime = $(this).attr('myVar');
hms = yourtime.split(':');
msecs = hms[0] * 3600000 + hms[1] * 60000 + hms[2]*1000;
seriesData_1.push(msecs);
做现在,我已经得到了它转换成毫秒,获得此画在与Y轴H:M:S
格式,你需要使用dateTimeLabelFormats
y axis
下,如下
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M:%S',
second: '%H:%M:%S',
minute: '%H:%M:%S',
hour: '%H:%M:%S'
},
让你的工具提示使用H:M:S
格式排列,添加此
tooltip: {
enabled: true,
formatter: function() {
var main = '<b>'+ Highcharts.dateFormat('%A, %b %e, %Y', this.x) +'</b>';
s = Math.floor(this.y/1000);
m = Math.floor(s/60);
s = s % 60;
h = Math.floor(m/60);
m = m % 60;
h = h % 24;
if (h < 9) h = "0" + h;
if (m < 9) m = "0" + m;
if (s < 9) s = "0" + s;
return '<b>'+ this.x +'</b><br>' + '<span style="color:green">Value-</span>' + [h, m, s].join(':');
}
},
希望这有助于为新手和我一样:)
什么DOE这与阿贾克斯呢?代码中的XMLHttpRequest对象在哪里? – epascarello
也许我正在密集,但已不是'20:57:13'已经在'小时:分钟:秒'格式? – Amadan
@epascarello这个代码是在高分辨率下的ajax模块 – Sathy