简体   繁体   English

高位图表(Highstock)在X轴折线图上绘制了不正确的日期

[英]Highcharts (highstock) plotting incorrect date on x-axis line chart

Here I have an example of a highstock chart I have generated: http://jsfiddle.net/9gTN8/ 这里有一个生成的高位图表的示例: http : //jsfiddle.net/9gTN8/

There are 3 data points with dates defined using the Date.UTC method. 使用Date.UTC方法定义的日期有3个数据点。 Despite the last date in the series being 2013-07-15 , the point is plotted in August. 尽管该系列的最后日期是2013-07-15 ,但该点已绘制在8月。 Likewise the other points appear to be being plotted a month ahead of where they should be. 同样,其他点似乎比它们应该提前一个月绘制。

I have used ordinal: false to allow for irregular date intervals, which is a feature of highstock. 我使用了ordinal: false来允许不规则的日期间隔,这是高库存的功能。

What is the reason for this and how can I solve it? 这是什么原因,我该如何解决?

Edit: 编辑:

My date in each datapoint is produced from php like so: 我在每个数据点中的日期都是由php生成的,如下所示:

echo "\n[Date.UTC(" . date("Y, m, d", strtotime($date)) . "), " . $value . "]";

I know I could have several php date() functions to decrement the month myself but I'd hope there'd be a more efficient way. 我知道我可以有几个php date()函数来自己减少月份,但我希望有一种更有效的方法。 Eg is it possible to replicate the javascript Date.UTC method in php and just output the big number (no. of milliseconds since 01/01/1970) straight off? 例如,是否可以在php中复制javascript Date.UTC方法并直接输出大数字(自1970年1月1日以来的毫秒数)?

The solution is to not use Date.UTC and just use php's date format like so: 解决方案是不使用Date.UTC而仅使用php的日期格式,如下所示:

echo "\n[" . 1000 * date("U", strtotime($date)) . ", " . $value . "]";

This will output the epoch timestamp as defined in the manual in seconds. 这将以秒为单位输出手册中定义的纪元时间戳。 Times by 1000 to get milliseconds as javaScript requires. 以1000的倍数获取javaScript所需的毫秒数。

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

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