首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含分钟的时间线yAxis格式:仅秒

问包含分钟的时间线yAxis格式:仅秒
EN

Stack Overflow用户
提问于 2013-08-27 18:46:13
回答 2查看 5.4K关注 0票数 1

我想画一张游泳者在几次比赛中的比赛时间。

对于系列数据,我使用php代码:

代码语言:javascript
复制
$datetime1=date('Y, m, d', strtotime($performances['PERF_DATE']."-1 month")); 
$datetime2='Date.UTC('.$datetime1.')';
$chrono=strtotime($performances['PERF_DATE']);
$data[] = "[$datetime2, $chrono]";

xAxis时间表是针对游泳比赛日期的:

代码语言:javascript
复制
xAxis: {
        type: 'datetime',
        dateTimeLabelFormats: { 
        day: '%d/%m/%Y'}

yAxis时间线用于比赛时间:

代码语言:javascript
复制
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‘);有人能帮我吗?非常感谢。

EN

回答 2

Stack Overflow用户

发布于 2013-08-27 19:35:18

你能展示一下你的data输出吗?对我来说,它工作得很好,请参见:http://jsfiddle.net/Fusher/pQ5EC/12/请确保,您的y值也是以毫秒为单位的时间戳。

代码语言:javascript
复制
    $('#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,],
        }]

    }); 
票数 1
EN

Stack Overflow用户

发布于 2013-08-29 05:33:04

抱歉,我之前确实回复了,但我的答案没有被系统保存-显然有8小时的停电时间,作者无法回答自己的问题。

我弄清楚了:在mysql中,我的时间格式是hh:mm:ss.00。我认为有一个函数可以很容易地将mysql时间格式转换为毫秒格式,但显然没有这个函数。因此,我使用以下代码手动将时间“爆炸”为毫秒:

代码语言:javascript
复制
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,它可以完美地工作。

谢谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18463287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档