简体   繁体   English

x轴带有日期和时间的高位图表(来自格式为YYYYMMDDHHMM的数据库)

[英]Highcharts with date and time for x axis (from a database with format YYYYMMDDHHMM)

I am trying to draw a graph using Highcharts for values with time and date for x axis. 我正在尝试使用Highcharts为x轴的时间和日期值绘制图形。 My database has the date values as YYYYMMDDHHMM (201409011345) and I want to plot y values with this date and time. 我的数据库的日期值为YYYYMMDDHHMM(201409011345),我想用此日期和时间绘制y值。 my code is as follows ; 我的代码如下;

<?php
while ($row = mysql_fetch_array($result)) {
   extract $row;
   $data[] = "[$datetime, $value]"; //here $datetime is like 201405242625 (YYYYMMDDHHMM)
}
?>
var chart = new Highcharts.Chart({
      chart: {
         renderTo: 'container'
      },
      series: [{
         data: [<?php echo join($data, ',') ?>]
      }]
});

Please give me any suggestions to get the correct datetime values for x axis 请给我任何建议以获取正确的x轴日期时间值

Thanks 谢谢

Your date value needs to either be in epoch format, or a Date.UTC object. 您的日期值必须为纪元格式或Date.UTC对象。

I'm not sure how well PHP will understand your date format, but assuming that it can, you can use the strtotime() function. 我不确定PHP将如何理解您的日期格式,但是假设可以,您可以使用strtotime()函数。

In you case, it would be 在您的情况下,

$date_stamp = strtotime($datetime) * 1000

You need the * 1000 because PHP uses epoch time in seconds, Javascript uses milliseconds. 您需要* 1000,因为PHP使用纪元时间(以秒为单位),而Javascript使用毫秒。

If PHP has a hard time interpreting your date format, you may need to format it within your database query, or use PHP's substr() function to break it up into its components and rebuild a readable date format. 如果PHP很难解释日期格式,则可能需要在数据库查询中对其进行格式化,或者使用PHP的substr()函数将其分解为各个组件并重建可读的日期格式。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM