我想画一张游泳者在几次比赛中的比赛时间。
对于系列数据,我使用php代码:
$datetime1=date('Y, m, d', strtotime($performances['PERF_DATE']."-1 month"));
$datetime2='Date.UTC('.$datetime1.')';
$chrono=strtotime($performances['PERF_DATE']);
$data[] = "[$datetime2, $chrono]";xAxis时间表是针对游泳比赛日期的:
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
day: '%d/%m/%Y'}yAxis时间线用于比赛时间:
yAxis: {
title : { text :'chronos'},
type: 'datetime', //y-axis will be in milliseconds
dateTimeLabelFormats: { //force all formats to be minute:second
second: '%M:%S',
minute: '%M:%S'
},
min: 0
}xAxis时间线工作得很完美。但是我的yAxis有一个格式问题:我不能以mm:ss格式显示时间。
我使用的是MySQL5.6.4,比赛时间(PERF_TIME)存储在类型time(2)列中,即包含秒的2个分数。比赛日期(PERF_DATE)存储在类型datetime列中。
例如,在php生成的表中,$performance‘’PERF_DATE‘将显示: 00:01:33.91。但是在Highcharts中,在yAxis上,该值将是16.Jan,而在绘图标签上,它将显示值1371333600。我猜那是微秒级的。我假设我需要在$chrono=strtotime上应用正确的时间格式函数($performances‘’PERF_DATE‘);有人能帮我吗?非常感谢。
发布于 2013-08-27 19:35:18
你能展示一下你的data输出吗?对我来说,它工作得很好,请参见:http://jsfiddle.net/Fusher/pQ5EC/12/请确保,您的y值也是以毫秒为单位的时间戳。
$('#container').highcharts({
chart: {
type: 'column'
},
xAxis: {
type: 'datetime'
},
yAxis: {
type: 'datetime'
},
series: [{
name: 'Temperatures',
pointStart: new Date().getTime(),
pointInterval: 24 * 3600 * 1000,
data: [1.5 * 60 * 1000,1.2 * 60 * 1000,2.5 * 60 * 1000,1.9 * 60 * 1000,],
}]
}); 发布于 2013-08-29 05:33:04
抱歉,我之前确实回复了,但我的答案没有被系统保存-显然有8小时的停电时间,作者无法回答自己的问题。
我弄清楚了:在mysql中,我的时间格式是hh:mm:ss.00。我认为有一个函数可以很容易地将mysql时间格式转换为毫秒格式,但显然没有这个函数。因此,我使用以下代码手动将时间“爆炸”为毫秒:
extract($performances);
//converts date from 2012-01-10 (mysql date format) to the format Highcharts understands 2012, 1, 10
$datetime1=date('Y, m, d', strtotime($performances['PERF_DATE']."-1 month"));
//getting the date into the required format for pushing the Data into the Series
$datetime2='Date.UTC('.$datetime1.')';
// value is in format hh:mm:ss.00
$chrono1=$performances['PERF_TIME'];
// explodes value in mn, sec and microseconds
sscanf($chrono1,"%d:%d:%d.%d",$hours,$minutes,$seconds,$milliseconds);
// calculate total of milliseconds
$chrono=$seconds * 1000 + $minutes * 60 * 1000 + $milliseconds * 10;
$data[] = "[$datetime2, $chrono]";也许有更干净的方法?但我现在可以将$data提供给Highcharts,它可以完美地工作。
谢谢。
https://stackoverflow.com/questions/18463287
复制相似问题