简体   繁体   中英

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/

There are 3 data points with dates defined using the Date.UTC method. Despite the last date in the series being 2013-07-15 , the point is plotted in August. 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.

What is the reason for this and how can I solve it?

Edit:

My date in each datapoint is produced from php like so:

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. 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?

The solution is to not use Date.UTC and just use php's date format like so:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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