我想画出一个游泳运动员在几次比赛中的比赛次数。
对于系列数据,我使用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格式显示时间。
我使用的是mysql 5.6.4,比赛时间(PERF_TIME)存储在type TIME(2)列中,即包括2个几分之一秒。比赛日期(PERF_DATE)存储在类型datetime列中。
例如,php生成的表中的$performances['PERF_DATE']将显示:00:01:33.91。但在Highcharts中,在yAxis上,值将为16.Jan,在绘图标签上,它将显示值1371333600。我想那是微秒。我想我需要在$chrono=strtotime($performances['PERF_DATE'])上应用正确的时间格式函数;有人能帮我吗?非常感谢。
您能显示您的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,],
}]
});
抱歉,我之前确实回复了,但系统没有保存我的答案——显然有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,它非常有效。
谢谢。